简体   繁体   中英

How to control the period of validation of the token in Firebase authentication?

In the previous version of Firebase it was possible to control the period for which the token after authentication would be valid . With the new version, we don't have this control. I can not find in the documentation clear explanation of what is happening.

I am using email and password authentication. with sdks 9.0.2 it seems there is no more problems. but I don't know how long my user will be authenticated as such .

I have a singleton FirebaseManager which listen for the state:

  public FirebaseManager() {
    // allow offline capability
    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    mAuth = FirebaseAuth.getInstance();

    FirebaseAuth.AuthStateListener authStateListener = firebaseAuth -> {
        FirebaseUser user = firebaseAuth.getCurrentUser();
        Log.v(TAG, "authStateListener, user: " + (user == null ? "is null" : user.getUid()));
    };
    mAuth.addAuthStateListener(authStateListener);
}

if i have signed in using:

mAuth.signInWithEmailAndPassword(email, pwd) ... 

in the listener above I'll receive a user. The next time I open my app, the user will still be signed in, and i still receive a user in the listener.

The unclear part is for how long? How firebase handles it? How long until i need to sign-in again? Do I need to sign in again with the same function every time i received a "user == null".

the fact of giving a user == null does not give us a lot of information and I am not sure how to implement that for a long term usage of the app by one user and make sure to keep the user session valid without any need to sign-in again.

If user is signed in using Email/password Auth then he will remain signed in forever until user logs-out/sign-out of the account.

To signout you can use this. mAuth.signOut();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM