Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

On an ionic/AngularJS/Cordova IOS app.

I'm trying to set a persistence login using mail/password (followed Firebase documentation : https://firebase.google.com/docs/auth/web/auth-state-persistence). But I can't figured out what is wrong with my code. My app is starting on the login page, when a user is clicking on the "Connexion button", it's trigger the login function.

The login is working, but when I'm closing the app (without logging out), restarting it, I'm still on the login page. The login is not persistent.

So I guess, one problem, might be the persistency call not well placed...Is it ? According to this post : Firebase 3.0 session persistance it could have someting related to firebase.auth().onAuthStateChanged(function(user), but I don't know...

// 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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...