How to automatically refresh expired id token using Firebase Admin SDK #2471
Unanswered
juniorforlife
asked this question in
Q&A
Replies: 2 comments
-
add onIdTokenChanged event handler using auth instance the call this api route
this will get triggered once the id token in the client expired and firebase explicitly creates a new one then make your fetch with the new idToken to always hava updated token |
Beta Was this translation helpful? Give feedback.
0 replies
-
This issue is probably related to your question, but no answer yet |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a SvelteKit app which uses Firebase Authentication. The auth flow is like this
/api/login/+server.ts
I will verify the id token given above and set my own SvelteKit cookieThe reason I don't use onAuthStateChanged is it only works on the client and will make a flash between logged-out and logged-in user
+hooks.server.ts
(a middleware file in SvelteKit) I will verify the id token on every request like thisThe problem I'm having is when
verifySessionCookie
throws an error ofauth/session-cookie-expired
I couldn't find any method to request a new id token on the server. In addition, I don't want to redirect the user to the login page which is annoying. How do I achieve this?Beta Was this translation helpful? Give feedback.
All reactions