4
votes

I added Firebase auth to my Reactjs (and Redux) web app and everything works perfectly. I'm using email / password sign in, and call firebase.auth().signInWithEmailAndPassword which persists on reloads, tab changes, etc. However, after about an hour, the auth session appears to expire and currentUser is set to null. It feels like there should be a setting somewhere in the Firebase console, but after searching through it, I can't find anything.

Any help would be really appreciated!

1
Is it the user session that is expiring or is it the token? ID tokens expire after one hour (which can't be changed), but are automatically refreshed behind the scene. User sessions don't expire after an hour. See stackoverflow.com/questions/37487283/…. - Adam Kipnis
I think that for whatever reason, the token isn't being refreshed automatically. That link suggests calling firebase.auth().currentUser.getToken to manually refresh, but I can't do that since currentUser is null after an hour. I guess I could set a 55 minute timer and refresh it that way, but it seems really hackish... Any ideas on why it isn't refreshing? - npalansky
User should not be logged out on ID token expiration. There is something else going on here. User is logged out if there is a big account change (user deleted, password changed, email changed, password reset, etc). Are you using firebase.auth().onAuthStateChanged listener to determine the initial state of a user? - bojeil
I set firebase.auth().onAuthStateChanged up last night with a console log, but it's not helping too much. Immediately after logging in, it logs what appears to be a normal logged in status containing an email, refreshToken, uid, etc. Refreshing the page logs the same thing, however after an hour goes by, the log just returns 'null'. After that time, refreshing still returns null and the only way to get the user data back is to log out and back in. - npalansky
Firebase tokens are by default set to live max 1hours. - STEEL

1 Answers

3
votes

I had the exact same issue, onAuthStateChanged was always triggered after 1 hour and the user was disconnected. And firebase.auth().currentUser.getIdToken(true) didn't help either, all because... Token Service API had to be enabled for my Google API key in the Google console. Problem solved!