diff --git a/src/auth/error.ts b/src/auth/error.ts index ddcdbad6fa..9a259ea5e5 100644 --- a/src/auth/error.ts +++ b/src/auth/error.ts @@ -95,6 +95,7 @@ export const AuthErrorCode = { MAXIMUM_USER_COUNT_EXCEEDED: 'maximum-user-count-exceeded', MISSING_UID: 'missing-uid', OPERATION_NOT_ALLOWED: 'operation-not-allowed', + PASSWORD_DOES_NOT_MEET_REQUIREMENTS: 'password-does-not-meet-requirements', PHONE_NUMBER_ALREADY_EXISTS: 'phone-number-already-exists', PROJECT_NOT_FOUND: 'project-not-found', INSUFFICIENT_PERMISSION: 'insufficient-permission', @@ -423,6 +424,10 @@ export const authClientErrorCode: { readonly [K in keyof typeof AuthErrorCode]: message: 'The given sign-in provider is disabled for this Firebase project. Enable it in the ' + 'Firebase console, under the sign-in method tab of the Auth section.', }, + PASSWORD_DOES_NOT_MEET_REQUIREMENTS: { + code: AuthErrorCode.PASSWORD_DOES_NOT_MEET_REQUIREMENTS, + message: 'The password does not meet the requirements.', + }, PHONE_NUMBER_ALREADY_EXISTS: { code: AuthErrorCode.PHONE_NUMBER_ALREADY_EXISTS, message: 'The user with the provided phone number already exists.', @@ -605,6 +610,8 @@ const AUTH_SERVER_TO_CLIENT_CODE: Record = { MISSING_USER_ACCOUNT: 'MISSING_UID', // Password auth disabled in console. OPERATION_NOT_ALLOWED: 'OPERATION_NOT_ALLOWED', + // Password does not meet the configured policy requirements. + PASSWORD_DOES_NOT_MEET_REQUIREMENTS: 'PASSWORD_DOES_NOT_MEET_REQUIREMENTS', // Provided credential has insufficient permissions. PERMISSION_DENIED: 'INSUFFICIENT_PERMISSION', // Phone number already exists. diff --git a/test/unit/utils/error.spec.ts b/test/unit/utils/error.spec.ts index 9d2cbc4521..cf06f93c51 100644 --- a/test/unit/utils/error.spec.ts +++ b/test/unit/utils/error.spec.ts @@ -138,6 +138,12 @@ describe('FirebaseAuthError', () => { 'There is no user record corresponding to the provided identifier.'); }); + it('should map password policy server errors to the public password policy code', () => { + const error = FirebaseAuthError.fromServerError('PASSWORD_DOES_NOT_MEET_REQUIREMENTS'); + expect(error.code).to.be.equal('auth/password-does-not-meet-requirements'); + expect(error.message).to.be.equal('The password does not meet the requirements.'); + }); + it('should initialize an error from an unexpected server code', () => { const error = FirebaseAuthError.fromServerError('UNEXPECTED_ERROR'); expect(error.code).to.be.equal('auth/internal-error');