[英]Firebase Auth login state persistence is not working
在ionic / AngularJS / Cordova IOS應用上。
我正在嘗試使用郵件/密碼設置持久性登錄( Firebase documentation
: https : Firebase documentation
)。 但是我無法弄清楚我的代碼出了什么問題。 我的應用程序從登錄頁面啟動,當用戶單擊“ Connexion按鈕”時,它會觸發登錄功能。
登錄正常,但是當我關閉應用程序(不注銷)並重新啟動它時,我仍然在登錄頁面上。 登錄名不是永久的。
所以我想,一個問題可能是持久性調用的位置不正確...對嗎? 根據這篇文章: Firebase 3.0會話持久性,它可能與firebase.auth firebase.auth().onAuthStateChanged(function(user)
,但是我不知道...
// EMAIL CONNEXION TRIGGERED WHEN CONNEXION BUTTON IS HIT $scope.loginEmail = function($email, $password){ firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION) .then(function() { var alertPopup; function signInSuccess(response) { $state.go("menu.VN"); } function signInError(response) { var errorCode = null; errorCode = response.code; if ($email === ""){ alertPopup = $ionicPopup.alert({ title: 'Something wrong...', cssClass: 'pop', template: '<div class="center-form">Need an email address...</div>' }); } } return firebase.auth().signInWithEmailAndPassword($email, $password) .then(signInSuccess) .catch(signInError); }) .catch(function(error) { // Handle persistence Errors here. var errorCode = error.code; var errorMessage = error.message; }); };
<label> <span>Email</span> <input type="email" placeholder="" ng-model="data.email"> </label> <label> <span>Password</span> <input type="password" placeholder="" ng-model="data.password"> </label> <button ng-click="loginEmail(data.email, data.password )">Connexion</button>
要保持狀態,您應該使用firebase.auth.Auth.Persistence.LOCAL
而不是firebase.auth.Auth.Persistence.SESSION
。
Cordova iOS應用程序中的localStorage
易變是已知問題。 Firebase Auth過去依賴於localStorage
但最新版本使用更可靠的indexedDB
來保留用戶狀態。 當此功能不可用時,它會退回到localStorage
。 在這種情況下,您可以將此Microsoft插件用於indexedDB 。
tldr; 遷移到最新版本的Firebase Auth並在indexedDB
不可用時使用Cordova indexedDB
插件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.