I'm curious about how to retrieve the correct error code in Firebase v10.
public resetPassword(email: string, actionCodeSettings: ActionCodeSettings): Promise<void> {
return sendPasswordResetEmail(this.auth, email, actionCodeSettings);
}
public async resetPassword(): Promise<void> {
try {
await this.resetPassword(this.email, this.actionCodeSettings);
} catch (error) {
if (error instanceof FirebaseError && error.message === AuthErrorCodes.INVALID_EMAIL) {
// This part never executes because AuthErrorCodes.INVALID_EMAIL = "auth/invalid-email" and error.message = "INVALID_EMAIL"
}
}
}
}
When I input an email that is not registered in Firebase, this code returns the following response:
{
"error": {
"code": 400,
"message": "INVALID_EMAIL",
"errors": [
{
"message": "INVALID_EMAIL",
"domain": "global",
"reason": "invalid"
}
]
}
}
The Firebase AuthErrorCodes
(link) use codes with an auth/
prefix. I want to access these codes from AuthErrorCode
(link), but they are internal. Is there a safe way to handle this error?