firebase / firebase/firebase-js-sdk
FR: (firebase/auth) bubble error code up from Identity Platform blocking function
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 37
Description
### [REQUIRED] Describe your environment
* Operating System version: MacOS Montery (12.6)
* Browser version: Chrome Version 107.0.5304.110 (Official Build) (arm64)
* Firebase SDK version: 9.10
* Firebase Product: auth
### [REQUIRED] Describe the problem
We use a custom blocking function (on_create) to sync Identity Platform users with a user profile service in our application. This function can fail for a number of expected ways (for example a user with a linked identity already existing, resulting in a 409 response). We throw errors with the documented error codes here: https://cloud.google.com/identity-platform/docs/blocking-functions#blocking_registration_or_sign-in
We would like to be able to detect the error-code used from our frontend auth integration using the firebase Javascript SDK so that we can display a localized contextual error message to the user.
#### Steps to reproduce:
- on_create blocking function triggered by Identity Platform throws an HttpsError with the code 'already-exists'
- Firebase SDK calls https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp and receives an error response that looks like this:
```json
{
"error": {
"code": 400,
"message": "BLOCKING_FUNCTION_ERROR_RESPONSE : HTTP Cloud Function returned an error: {\"error\":{\"code\":409,\"message\":\"This Identity is already assigned to a user.\",\"status\":\"ALREADY_EXISTS\"}}",
"errors": [
{
"message": "BLOCKING_FUNCTION_ERROR_RESPONSE : HTTP Cloud Function returned an error: {\"error\":{\"code\":409,\"message\":\"This Identity is already assigned to a user.\",\"status\":\"ALREADY_EXISTS\"}}",
"domain": "global",
"reason": "invalid"
}
]
}
}
```
- Firebase SDK throws an error caught by our client side code with the following attributes:
- - code: "auth/internal-error"
- - message: "Firebase: HTTP Cloud Function returned an error: {\"error\":{\"code\":409,\"message\":\"This Identity is already assigned to a user.\",\"status\":\"ALREADY_EXISTS\"}} (auth/internal-error)."
It would be preferable if the original code (already-exists) were available on the Firebase thrown error as a single attribute so that we can display an appropriate, localized error message to the user. Currently we would have to creatively parse out the error object embedded in the message attribute.
Contributor guide
Assessment
This issue has not been assessed yet.