Search code examples
ionic-frameworkfirebaseangularfirefirebase-authenticationionic-view

Ionic/Firebase: Log in after logging out doesn't work


I am building an Ionic/Phonegap app with a Firebase backend.

Login

Followed the example from the official AngularFire documentation for login:

// Check sign-in data
$scope.signIn = function(user, password) {

    // Log in
    $scope.auth.$authWithPassword({
        email    : user,
        password : password
    })

    // If successful
    .then(function(authData) {
        console.log('worked');
        // Further code
    }

    // If failure, alert
    .catch(function(error) {

        console.log(error);
    }
}

Login works fine.

Logout

For logout I also copied the example from the documentation:

$scope.logout = function() {

    // Manually disconnect from database
    Firebase.goOffline();

    // Log user out
    $scope.auth.$unauth();

    // Go to landing page
    $state.go('signin');
};

Seems to work as well (when I'm asking for the current authentication state of the user after logging out $getAuth() returns null).

Login after Logout

But if I'm now trying to log in again, nothing happens - no error, no success message. So neither of the console.logs triggers.

I need to close and open the app again or refresh the browser window in order to be able to log in again. Can anyone tell me what I'm doing wrong here?


Versions

Using the latest versions:

Ionic 1.2.4

Firebase 2.4.0

AngularFire 1.1.3


Solution

  • Remove the Firebase.goOffline() from your logout. If you want to manually manage Firebase connection then you should consider adding Firebase.goOnline() during login.

    Auth.$unauth() will take care of logging out the user, you do not have to disconnect Firebase manually.