Persisting authentication state #4679
-
Hi! We want users to stay signed in to our app forever (or at least a very long time) so they don't have to re-authenticate so often, but I'm not sure how to implement this. AFAIK This might be similar to #980, although it looks like the state does not persist for any of our users. The state persist fine within a session but the session just expires every hour or so. This is how we implemented the
It looks like using refresh tokens will solve our issue since they don't expire, but they're not supported by this library. Is that still a work in progress or is there another way to keep the user signed in? Thanks! 🔥 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
This is strange, I don't have this issue with my app, using react-native-firebase. The auth tokens are apparently refreshed just fine. We have noticed issues with other people having tokens cycle unexpectedly, with e.g. react-native-push-notifications and onesignal among other third party libraries. I encourage you to try it with an otherwise empty project, like from https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh and my hypothesis is that you will have stable / continued logins + tokens and not reproduce this. |
Beta Was this translation helpful? Give feedback.
-
I think I found the issue - @mikehardy thanks for your feedback. We're using the For some reason I thought that the Hope this makes sense to anyone who's running into a similar issue. |
Beta Was this translation helpful? Give feedback.
I think I found the issue - @mikehardy thanks for your feedback.
We're using the
idToken
as access token for our own API, and validate that token on the backend with the Firebase Admin SDK. On the frontend we listen to theonAuthStateChanged
event to retrieve the user'sidToken
and save theidToken
inAsyncStorage
. We get theidToken
fromAsyncStorage
every time we make an API call to our own backend.For some reason I thought that the
onAuthStateChanged
event would get triggered when theidToken
refreshes, but this is not the case. The RNFB SDK just refreshed the token silently, and you will get the updated token when you callauth().currentUser.getIdToken()
. So right now instead of gett…