--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/832c7dcf-114e-48d0-b605-2ffed45eb074o%40googlegroups.com.
Hello MAW,Firebase manages auth state on your behalf and it doesn't expire after 1 hour. You shouldn't need to do anything here to keep your users logged in. If auth state is expiring, then something else is likely going wrong.Behind the scenes, Auth works as follows:
- Sign in with your preferred provider (email/pass, oauth, custom tokens, et al)
- Exchange that token for a Firebase Auth ID token
- Behind the scenes, Firebase also mints a refresh token
- At the end of an hour, the Auth ID token expires, but is automatically renewed as needed by using the refresh token
The Auth ID token and refresh token are stored in the devices local storage. Clearing that cache would of course cause the user to be logged out.☼, Kato
On Wed, Jul 29, 2020 at 8:30 AM MAW <m.abo...@gmail.com> wrote:
I have been using firebase for 6 months now and I didn't pay attention to keeping the user logged in indefinitely till now, and everything was going fine. The token expires after 1 hour and the onAuthStateChanged() gets fired with a user=null. This is where I set the logic to sign the user out and navigate to the login page.--Now I'm developping a PWA, where it will be installed on mobile devices (added to the home screen), and the users must be signed in all the time.I have been reading through the documentation and the firebase group here, and I got that using signInWithCustomToken() should solve the issue, but again, the custom token is still expiring after 1 hour and the onAuthStateChanged() gets fired again with user=null. And hence the user gets logged out with a redirection to the login page.I have a firebase function that generates the custom token and sends it to the front-end, then the front-end uses this token to signInWithCustomToken(), hoping it will keep the session up, but still happening only for 1 hour!This doesn't happen on the computer, when using the browser and the browser is set to always continue from where the user left!It only happens on the mobile devices, where the PWA is installed (added to the home screen)I got from all what I read that the user session doesn't expire, but the token does! These are my questions
- If the user session is never expiring, until an explicit sign out, why does the onAuthStateChanged() fires with a user=null?!
- In this case how to handle the sign in logic, and the onAuthStateChanged() properly, so the user session stays alive in the PWA, and the application stays working in the background?!!
Any help, example would be very much appreciated.Thanks in advance.
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/832c7dcf-114e-48d0-b605-2ffed45eb074o%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/84218fc5-99fa-4ebb-af96-3bc1c05a4a24o%40googlegroups.com.
You don't need to setPersistence to LOCAL; that's already the default. There's no need to call firebase.auth().signInWithEmailAndPassword(...) during each app init. This calls signOut() first (causing onAuthStateChanged to report a null) and then reauthenticates the user. Instead, you should use onAuthStateChanged() to see if the user is already authenticated.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/84218fc5-99fa-4ebb-af96-3bc1c05a4a24o%40googlegroups.com.
You don't need to setPersistence to LOCAL; that's already the default. There's no need to call firebase.auth().signInWithEmailAndPassword(...) during each app init. This calls signOut() first (causing onAuthStateChanged to report a null) and then reauthenticates the user. Instead, you should use onAuthStateChanged() to see if the user is already authenticated.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/84218fc5-99fa-4ebb-af96-3bc1c05a4a24o%40googlegroups.com.