Skip to content

auth: generatePasswordResetLink returns auth/internal-error on valid non-registered email address #1202

@loukotal

Description

@loukotal

Describe your environment

  • Operating System version: macOS 10.15.7
  • Firebase SDK version: 9.4.2
  • Firebase Product: auth
  • Node.js version: 14.16.0
  • NPM version: 6.14.11

Describe the problem

Calling generatePasswordResetLink with a valid email that is "not registered" (or, in other words, is not tied to any user), results in auth/internal-error. We used to catch auth/user-not-found error code for cases where the email was not found, but it seems like the error code changed to EMAIL_NOT_FOUND. EMAIL_NOT_FOUND is not handled/mapped and therefore the response results in auth/internal-error. The error code is not present in the docs here, is it not handled on purpose then?
I would have thought an error code like this is something that could have its own error code and not default to auth/internal-error, hence this issue.

Or is to something to be reported on the official Firebase bug report site here? If so, then I am sorry for opening the issue here and I will report it on the Firebase website.

Relevant pieces of code I could (or could not) find:

I also went through the python sdk and it seems like EMAIL_NOT_FOUND is also not handled. Maybe it is on purpose then?

Steps to reproduce:

  1. Initialize firebase-admin app with a service account
  2. Call generatePasswordResetLink with a valid email that is not tied to any user
  3. Catch error

Or curl command to REST API for quick testing:

curl 'https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=API_KEY' \
-H 'Content-Type: application/json' \
--data-binary '{"requestType":"PASSWORD_RESET","email":"[email protected]@example.com"}'

Error info:

{
    code: 'auth/internal-error',
    message: 'An internal error has occurred. Raw server response: "{"error":{"code":400,"message":"EMAIL_NOT_FOUND","errors":[{"message":"EMAIL_NOT_FOUND","domain":"global","reason":"invalid"}]}}"'
  },
  codePrefix: 'auth'
}

Relevant Code:

import * as admin from "firebase-admin";

admin.initializeApp({
    credential: admin.credential.cert("GCP_SERVICE_ACCOUNT")
})

admin.auth().generatePasswordResetLink("[email protected]").catch(console.error).finally(process.exit);

Expected behaviour

EMAIL_NOT_FOUND is defined in AuthClientErrorCode and correctly mapped so that error.code does not return auth/internal-error but auth/email-not-found (or similar).


I will gladly provide more information if needed and if this is something that should be added, I think I would manage to make a PR for it. I have it mostly ready, but I am not sure if it is a desired behaviour to handle this error code, since it is not handled in the python sdk as well (from what I could gather).

Thank you!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions