我想知道是否有人使用離子和firebase並允許持久性驗證。當我創建IPA/APK並將應用程序下載到我的設備時,每當我關閉應用程序時,我都必須重新登錄。Ionic Framework和Firebase持久驗證驗證
使用$ authWithPassword登錄時,回調函數包括uid和令牌。如果我使用導入ngStorage作爲依賴項,如何使用uid和令牌來保持auth?
對於登錄,用戶登錄調用登錄功能,該功能鏈接到我的工廠中的Auth.login功能。
login: function(user) {
return auth.$authWithPassword({
email: user.email,
password: user.password
}, function(error, authData) {
switch(error.code) {
case "INVALID_EMAIL":
console.log("Log in with a valid email.");
break
case "INVALID_PASSWORD":
console.log("Password or email is incorrect");
break
default:
console.log("Enter a valid email and password");
}
})
.then(function(authData) {
console.log("login: Logged in with uid: ", authData);
$localStorage.uid = authData.uid;
$localStorage.token = authData.token;
})
.catch(function(error) {
alert("Error: " + error);
});
我不知道我將如何堅持用uid和令牌認證。沒有用戶密碼可以做到嗎?
在此先感謝您的幫助。
您不應該使用'localstorage'來保存這種類型的數據[因爲它被清理](http://ionicframework.com/docs/v2/api/platform/storage/LocalStorage/)。它將數據存儲在設備的緩存中,隨時可以在設備需要資源時進行清理。 – peteb