Skip to content
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

Handle failure to verify refreshed token #679

Merged

Conversation

valeriangalliat
Copy link
Contributor

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.

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
Copy link

vercel bot commented Sep 8, 2023

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

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Nov 5, 2023

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

Copy link

codecov bot commented Nov 5, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

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

📢 Thoughts on this report? Let us know!.

@kmjennison kmjennison merged commit fe4666d into gladly-team:v1.x Nov 5, 2023
4 of 5 checks passed
Copy link
Contributor

@kmjennison kmjennison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thank you for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants