-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔥 [🐛?] Auth: listener passed to onIdTokenChanged()
not being called on token refresh
#8181
Comments
I encourage you to update to current versions and make sure it is still there. There was a related problem fixed on android but it was failure to call items after hot reload. It would not have affected iOS and you don't mention hot reload, but who knows - logging on old versions is frequently unproductive as things may have been fixed after If you can still reproduce, I'd love to hear what we need to do for a minimal test case to show the problem Starting from But otherwise the app is just one page. You can hack in buttons as I did to test basic things and it would be great to know what we can put in there to trigger this quickly and confirm there's a repo problem vs a project-specific problem |
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions. |
Fyi we never found a solution for this, and i'm currently trying with setting a timeout that simply force refreshes the token, and force refreshing when the app comes back in focus, etc. Would love for this to just work out of the box. |
I'm still not sure exactly how to reproduce this, and it is because I've personally never seen it. When I tried to think through why in response to your comment that it is still happening, I realized I never stored the token. Why would I? The user is local, the token is local. You can always get the user from auth, and get the token from the user. There's no need for the app to store it anywhere, firebase is already storing it for you and you always have device-local access to it from firebase APIs. Perhaps that's a real way forward. That said, the listener should be called if it's documented behavior, not disagreeing there |
Yeah, i'm also stumped. To be clear we're only storing the token for a particular case where i couldn't find a way to await But even then if the Is there a way i could debug this and/or give you more info? |
Some other info:
If i'm missing anything i can definitely work through it, but the docs are sober on details and i understand that simply getting to call And there's no way to shorten the expiration period of the token, is there? Which would make debugging easier. |
Thanks for the extra info For reproduction: I don't believe there is a way to shorten it declaratively, no, it defaults to an hour but apparently after 55 minutes, the firebase SDKs begin attempting to refresh, citation from firebase support team: https://stackoverflow.com/questions/62389267/how-to-handle-firebaseauth-token-expiration#62390404 I had forgotten that getIdToken was async, as it may need to wait on a refresh, though in practice the token should be valid at all times and thus may be a synchronous experience there is the chance it really has to sit on the network and wait (or timeout and return null...) An idea though - If you send 'forceRefresh' true to getIdToken() on User, that should fetch a new token and...that should call the listener shouldn't it? https://firebase.google.com/docs/reference/js/auth.user.md#usergetidtoken That bears testing in pure firebase-js-sdk to see if it behaves that way and also you could test it immediately to see if you get different tokens from calling getIdToken(false) then getIdToken(true). If that works and if firebase-js-sdk calls the listener in that case, it can be a good test for the listener here - we could add that to the e2e suite even |
So you recommend we just force refresh the token on each API call? ( |
Oh no - that would be very very expensive and I think on the backend google would auto-detect that as a mild form of abuse and start rate-limiting you which would be a nightmare. I was thinking purely as how to reproduce this in a deterministic amount of time so we can expose the problem and fix this issue (assuming it reproduces). So it's more of a "does this even work as a way to reproduce?" question that needs a little proof, not a recommendation for your general case. Sorry that wasn't clear |
Ah sorry for misunderstanding, yeah that makes sense. I just tried it and yes, if i force refresh tokens on each API call then the listener for |
Okay - that's good to know. Very very interesting that isn't called on the auto-refresh case but is on the force-refresh case. Thanks for the information. Path forward for investigation / fix: As a maybe-better workaround, you can use the standard pure-javascript jwt library to parse the token and know the real expiry time if you aren't already. That could be used to inform your timeout / force fetch workaround to be as efficient as possible - only comparing stored vs current / force fetching when close to expiry |
Issue
Hi all! The ID token is refreshed but my listener is never called, thus the app-wide Redux state is not updated with the new token and my app ends up using an expired Firebase token.
I'm trying to understand if this is a setup issue somehow, but the rest seems to work correctly. I'm using Android but my colleagues are on iOS and having a similar problem. Issue goes away if user restarts the app, obviously. We are using Expo & EAS, if it's of any help.
Project Files
Javascript
Click To Expand
package.json
:firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:# N/A
AppDelegate.m
:// N/A
Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:// N/A
android/app/build.gradle
:// N/A
android/settings.gradle
:// N/A
MainApplication.java
:// N/A
AndroidManifest.xml
:<!-- N/A -->
Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:21.2.0
Firebase
module(s) you're using that has the issue:Auth
TypeScript
?Yes
&5.3.3
(Sorry if i'm missing some valuable info for debugging, haven't touched RN in some time so a lot of it is new for me; just ask and i'll provide!)
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: