question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getIdToken never refreshes the token client side

See original GitHub issue

Describe the bug It’s possible this is an error on my side rather than with the package. However, I think my use case is pretty simple.

I’m making an authenticated API call server side and then making the same API call client side when a user wants to refresh data on the page. The API call is to a separate (non nextjs) backend. If I open the page, leave it open for about an hour without reloading the page, and then click my refresh data button, I get the following error on my backend when verifying the ID token: ID token has expired at: 1634752738 (time changes obviously).

My API request is pretty simple, it’s just

authUser.getIdToken()
.then((token) => axios.get(url, {headers: { Authorization: token }}))

Unless I’m missing something, getIdToken should handle refreshing the token if it has expired, per the firebase docs. It does not appear to refresh the ID token ever—I am logging the token expiration date on my backend and it only changes when I reload the page, never when I make the request client side. Even when I pass true to force refresh the token, the expiration doesn’t change and eventually it gives me an error.

Any idea why this might be happening?

Versions

next-firebase-auth version: ^0.13.4-alpha.0 Firebase JS SDK: ^8.6.8 Next.js: 11.0.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kmjennisoncommented, Oct 25, 2021

Thanks, I’ll dig into this as soon as I can make the time.

0reactions
kmjennisoncommented, Dec 29, 2021

Closing until there’s a clear way to reproduce.

Read more comments on GitHub >

github_iconTop Results From Across the Web

onIdTokenChanged never called when token refreshes #2985
The token refreshes lazily when interacting with other Firebase services (or if you call getIdToken(true) ). Is your API using another ...
Read more >
error retrieving user Id token assigned by firebase in the client ...
First, I'd recommend updating Firebase SDK to latest version which is 8.9.1 at the time of writing this.
Read more >
Demystifying Firebase Auth Tokens | by Jacob Wenger | Medium
Although you will likely never need to interact with refresh tokens directly, it is important to know they exist as they are a...
Read more >
Verify ID Tokens | Firebase Authentication - Google
Warning: The ID token verification methods included in the Firebase Admin SDKs are meant to verify ID tokens that come from the client...
Read more >
How to handle expired user ID token with Firebase? - Reddit
I saw that Firebase refreshes the ID token on its own. ... the token has changed => onIdTokenChanged() , but the token is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found