gladly-team / next-firebase-auth

Simple Firebase authentication for all Next.js rendering strategies
https://nfa-example-git-v1x-gladly-team.vercel.app/
MIT License
1.33k stars 290 forks source link

Handle failure to verify refreshed token #679

Closed valeriangalliat closed 8 months ago

valeriangalliat commented 10 months ago

If the existing token is expired, and we refresh it successfully, we still need to call veirfyIdToken in order to get the firebaseUser, which is required by createUser below.

Currently, if verifyIdToken with the newly refreshed token fails, the error handler is called, but the code passes through, calling createUser with a token but firebaseUserAdminSDK: undefined, which causes the following error:

Error: The "token" value can only be set if the "firebaseUserAdminSDK" property is defined.

In order to prevent this, we need to set newTokenFailure = true in case verifyIdToken fails with the newly refreshed token.

FWIW this never happened to me in production, but happens quite often when developing with the Firebase emulators.

vercel[bot] commented 10 months ago

@valeriangalliat is attempting to deploy a commit to the Gladly Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] commented 8 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nfa-example ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2023 7:03pm
codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Files Coverage Δ
src/firebaseAdmin.ts 91.96% <100.00%> (+0.07%) :arrow_up:

:loudspeaker: Thoughts on this report? Let us know!.