Skip to content

fix(react): rethrow FirebaseUIError from the email form action hooks - #1532

Open
demolaf wants to merge 3 commits into
mainfrom
fix/react-hooks-firebaseuierror
Open

demolaf wants to merge 3 commits into
mainfrom
fix/react-hooks-firebaseuierror

Conversation

@demolaf

@demolaf demolaf commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Makes the sign-in, sign-up, forgot-password and email-link action hooks always reject with a FirebaseUIError, so React apps keep its code and cause instead of getting a plain Error.

Changes

  • The four use*AuthFormAction hooks rethrow the FirebaseUIError as-is, matching the phone and MFA hooks. The message users see is unchanged.
  • Errors that are not from Firebase reject with a FirebaseUIError from the new core createUnknownFirebaseUIError: code ui/unknown-error, the translated unknownError message, the original message on cause and the original error at cause.cause.
  • shadcn email forms now show these errors without the old "Error: " prefix. Apps that only check instanceof Error are unaffected.
  • The README documents the helper, the ui/unknown-error shape and the hooks' rejection type.

Maintainer note: Fixes internal CPRN-506

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the React authentication form action hooks (useEmailLinkAuthFormAction, useForgotPasswordAuthFormAction, useSignInAuthFormAction, and useSignUpAuthFormAction) to rethrow the original FirebaseUIError instance directly rather than wrapping its message in a generic Error. This change ensures that critical error properties, such as code and cause, are preserved for callers. Additionally, corresponding unit tests have been added to verify this behavior across all modified forms. I have no further feedback to provide as the changes are well-implemented and fully tested.

@demolaf
demolaf marked this pull request as ready for review November 4, 2026 14:22

@russellwheatley russellwheatley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A couple of things on the ui/unknown-error shape.

Comment thread packages/react/src/utils/errors.ts Outdated
*/
export function createUnknownFirebaseUIError(ui: FirebaseUI, error: unknown): FirebaseUIError {
const unknownError = new FirebaseError("ui/unknown-error", getTranslation(ui, "errors", "unknownError"));
unknownError.cause = error;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For ui/unknown-error the original error ends up at err.cause.cause, and err.cause is a synthetic FirebaseError with the translated message. That doesn't quite match the README errors section ("keep the original Firebase error as cause... untranslated message"). Might be worth a line in that README section saying where to find the original for ui/unknown-error, or I'm open to a flatter shape if you think it's cleaner.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Flattened it: err.cause now carries the original error's untranslated message, with the original error at err.cause.cause, and the README errors section says so.

Comment thread packages/react/src/utils/errors.ts Outdated
* @param error - The original error.
* @returns A FirebaseUIError for the unknown error.
*/
export function createUnknownFirebaseUIError(ui: FirebaseUI, error: unknown): FirebaseUIError {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since ui/unknown-error is now a code consumers can see, I think this helper might belong in core next to FirebaseUIError so Angular (or anything else) can produce the same error.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, moved to core as createUnknownFirebaseUIError next to FirebaseUIError, and ui/unknown-error now maps to unknownError in ERROR_CODE_MAP.

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