Skip to content

Commit ac48659

Browse files
committed
Expose INVALID_LOGIN_CREDENTIALS as auth/invalid-credential error.
Update the doc snippets for various SDK methods to explain the behavior when Email Enumeration Protection is enabled. Mark fetchSignInMethodsForEmail and updateEmail as deprecated.
1 parent 3533b32 commit ac48659

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

common/api-review/auth.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export const AuthErrorCodes: {
165165
readonly INVALID_EMAIL: "auth/invalid-email";
166166
readonly INVALID_EMULATOR_SCHEME: "auth/invalid-emulator-scheme";
167167
readonly INVALID_IDP_RESPONSE: "auth/invalid-credential";
168+
readonly INVALID_LOGIN_CREDENTIALS: "auth/invalid-credential";
168169
readonly INVALID_MESSAGE_PAYLOAD: "auth/invalid-message-payload";
169170
readonly INVALID_MFA_SESSION: "auth/invalid-multi-factor-session";
170171
readonly INVALID_OAUTH_CLIENT_ID: "auth/invalid-oauth-client-id";

packages/auth/src/api/errors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const enum ServerError {
4444
INVALID_ID_TOKEN = 'INVALID_ID_TOKEN',
4545
INVALID_IDP_RESPONSE = 'INVALID_IDP_RESPONSE',
4646
INVALID_IDENTIFIER = 'INVALID_IDENTIFIER',
47+
INVALID_LOGIN_CREDENTIALS = 'INVALID_LOGIN_CREDENTIALS',
4748
INVALID_MESSAGE_PAYLOAD = 'INVALID_MESSAGE_PAYLOAD',
4849
INVALID_MFA_PENDING_CREDENTIAL = 'INVALID_MFA_PENDING_CREDENTIAL',
4950
INVALID_OAUTH_CLIENT_ID = 'INVALID_OAUTH_CLIENT_ID',
@@ -144,6 +145,10 @@ export const SERVER_ERROR_MAP: Partial<ServerErrorMap<ServerError>> = {
144145
[ServerError.INVALID_PASSWORD]: AuthErrorCode.INVALID_PASSWORD,
145146
// This can only happen if the SDK sends a bad request.
146147
[ServerError.MISSING_PASSWORD]: AuthErrorCode.MISSING_PASSWORD,
148+
// Thrown if Email Enumeration Protection is enabled in the project and the email or password is
149+
// invalid.
150+
[ServerError.INVALID_LOGIN_CREDENTIALS]:
151+
AuthErrorCode.INVALID_LOGIN_CREDENTIALS,
147152

148153
// Sign up with email and password errors.
149154
[ServerError.EMAIL_EXISTS]: AuthErrorCode.EMAIL_EXISTS,

packages/auth/src/core/errors.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const enum AuthErrorCode {
6161
INVALID_EMAIL = 'invalid-email',
6262
INVALID_EMULATOR_SCHEME = 'invalid-emulator-scheme',
6363
INVALID_IDP_RESPONSE = 'invalid-credential',
64+
INVALID_LOGIN_CREDENTIALS = 'invalid-credential',
6465
INVALID_MESSAGE_PAYLOAD = 'invalid-message-payload',
6566
INVALID_MFA_SESSION = 'invalid-multi-factor-session',
6667
INVALID_OAUTH_CLIENT_ID = 'invalid-oauth-client-id',
@@ -219,6 +220,8 @@ function _debugErrorMap(): ErrorMap<AuthErrorCode> {
219220
'The SHA-1 certificate hash provided is invalid.',
220221
[AuthErrorCode.INVALID_IDP_RESPONSE]:
221222
'The supplied auth credential is malformed or has expired.',
223+
[AuthErrorCode.INVALID_LOGIN_CREDENTIALS]:
224+
'The supplied login credentials are invalid.',
222225
[AuthErrorCode.INVALID_MESSAGE_PAYLOAD]:
223226
'The email template corresponding to this action contains invalid characters in its message. ' +
224227
'Please fix by going to the Auth email templates section in the Firebase Console.',
@@ -528,6 +531,7 @@ export const AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY = {
528531
INVALID_EMAIL: 'auth/invalid-email',
529532
INVALID_EMULATOR_SCHEME: 'auth/invalid-emulator-scheme',
530533
INVALID_IDP_RESPONSE: 'auth/invalid-credential',
534+
INVALID_LOGIN_CREDENTIALS: 'auth/invalid-credential',
531535
INVALID_MESSAGE_PAYLOAD: 'auth/invalid-message-payload',
532536
INVALID_MFA_SESSION: 'auth/invalid-multi-factor-session',
533537
INVALID_OAUTH_CLIENT_ID: 'auth/invalid-oauth-client-id',

packages/auth/src/core/strategies/email.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ import { _setActionCodeSettingsOnRequest } from './action_code_settings';
3333
import { getModularInstance } from '@firebase/util';
3434

3535
/**
36-
* Gets the list of possible sign in methods for the given email address.
36+
* Gets the list of possible sign in methods for the given email address. This method returns an
37+
* empty list when [Email Enumeration Protection](https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection) is enabled, irrespective of the number of
38+
* authentication methods available for the given email.
3739
*
3840
* @remarks
3941
* This is useful to differentiate methods of sign-in for the same provider, eg.

packages/auth/src/core/strategies/email_and_password.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ async function recachePasswordPolicy(auth: Auth): Promise<void> {
6161
}
6262

6363
/**
64-
* Sends a password reset email to the given email address.
64+
* Sends a password reset email to the given email address. This method does not throw an error when
65+
* [Email Enumeration Protection](https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection) is enabled.
6566
*
6667
* @remarks
6768
* To complete the password reset, call {@link confirmPasswordReset} with the code supplied in
@@ -303,6 +304,8 @@ export async function createUserWithEmailAndPassword(
303304
*
304305
* @remarks
305306
* Fails with an error if the email address and password do not match.
307+
* When [Email Enumeration Protection](https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection) is enabled,
308+
* this method fails with "auth/invalid-credential" in case of an invalid email/password.
306309
*
307310
* Note: The user's password is NOT the password used to access the user's email account. The
308311
* email address serves as a unique identifier for the user, and the password is used to access

packages/auth/src/core/user/account_info.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export async function updateProfile(
8888
* @param user - The user.
8989
* @param newEmail - The new email address.
9090
*
91+
* Throws "auth/operation-not-allowed" error when [Email Enumeration Protection](https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection) is enabled.
92+
* Deprecated - Use {@link verifyBeforeUpdateEmail} instead.
93+
*
9194
* @public
9295
*/
9396
export function updateEmail(user: User, newEmail: string): Promise<void> {

0 commit comments

Comments
 (0)