0
votes

i need a simple solution about auto-login to the app;

basically the app should start and try to go TabsPage, and if there is no auth, should go to the LoginPage. after log in, app will not log out until actual user taps logout button.

i only found that document: click

firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
  .then(function() {

at there i edited this like that:

  persistentLogin() {

    this.afAuth.auth.setPersistence(firebase.auth.Auth.Persistence.LOCAL)
  .then(function() {
    // Existing and future Auth states are now persisted in the current
    // session only. Closing the window would clear any existing state even
    // if a user forgets to sign out.
    // ...
    // New sign-in will be persisted with session persistence.
    return this.login();
  })
  .catch(function(error) {
    // Handle Errors here.

  });

  }

but on this code i am taking an error on this ones "firebase", i tried this.afAuth.auth is not working also:

firebase.auth.Auth.Persistence.LOCAL

There is not much document about this thing on the internet, anyone knows the deal ? thanks for reading ..

1

1 Answers

1
votes

Firebase Auth sessions are indefinite. User should remain logged in unless explicitly signed out. Make sure you check firebase.auth().onAuthStateChanged() to detect if a user is signed in or not when the app launches or is reloaded.

Also you may want to use firebase.auth.Auth.Persistence.LOCAL as firebase.auth.Auth.Persistence.SESSION will be lost once the tab is closed.