Skip to content

Commit

Permalink
Handle failure to verify refreshed token (#679)
Browse files Browse the repository at this point in the history
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.

Co-authored-by: Kevin Jennison <kevin.jennison1@gmail.com>
  • Loading branch information
valeriangalliat and kmjennison authored Nov 5, 2023
1 parent 37069af commit fe4666d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/firebaseAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export const verifyIdToken: VerifyIdToken = async (
} else {
logDebug(verifyErr)
}

newTokenFailure = true
}
}

Expand Down

0 comments on commit fe4666d

Please sign in to comment.