简体   繁体   中英

Firebase onAuthStateChanged works but doesn't update lastSignInTime

I'm using both Google Sign in and Email and Password authentication in my react native application. I set up a listener for the authstate and it all works fine, my users are authenticated, the application proceeds to the Main Screen and all.

However, when looking at the "authentication tab" on the Firebase Console, my users have both the last sign in and created at to be the same time, despite how many times users have logged in after that.

I noticed that if I log out and log back in, the "last logged in" tab, changes the value. That means that sign in with "signInAndRetrieveDataWithCredential" which gets called when my users log in, does change that value, but the auth state listener, which is then listening to the persistence of my users, doesn't update it. I think that would be very important, since the users are opening your app and "signing in", even though they don't go through a login flow.

What can I do to update the value and have an updated list of when users were created and last signed in? That seems like some important information to keep track of how your users are using your app and if they are coming back.

A listener just detects a change in state. It doesn't force a change in state. The last sign in time is the time that the user was previously fully logged out, then your app used a sign in API to sign in. It's not the last time that your listener detected a prior sign in.

When the user signs in, that sign in is effectively permanent . The sign in doesn't expire until the user explicitly signs out (when your code calls the sign out API), or the system rejects the automatic refresh of their sign in (the account is deleted or disabled).

If you want to know the last time your authentication state listener triggered, you can store that on your own, but I don't think it will necessarily give you very useful information. The best is that you will know roughly the last time they were actively using your app.

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