From afb9530800a0ed4c837b0c6e10aa698de1345352 Mon Sep 17 00:00:00 2001 From: Sean Li <22557931+sean0407@users.noreply.github.com> Date: Tue, 20 Oct 2026 06:23:15 +0800 Subject: [PATCH 1/2] fix(auth): map password policy server error --- src/auth/error.ts | 7 +++++++ test/unit/utils/error.spec.ts | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/auth/error.ts b/src/auth/error.ts index ddcdbad6fa..2451627576 100644 --- a/src/auth/error.ts +++ b/src/auth/error.ts @@ -64,6 +64,7 @@ export const AuthErrorCode = { INVALID_PASSWORD: 'invalid-password', INVALID_PASSWORD_HASH: 'invalid-password-hash', INVALID_PASSWORD_SALT: 'invalid-password-salt', + PASSWORD_DOES_NOT_MEET_REQUIREMENTS: 'password-does-not-meet-requirements', INVALID_PHONE_NUMBER: 'invalid-phone-number', INVALID_PHOTO_URL: 'invalid-photo-url', INVALID_PROJECT_ID: 'invalid-project-id', @@ -297,6 +298,10 @@ export const authClientErrorCode: { readonly [K in keyof typeof AuthErrorCode]: code: AuthErrorCode.INVALID_PASSWORD_SALT, message: 'The password salt must be a valid byte buffer.', }, + PASSWORD_DOES_NOT_MEET_REQUIREMENTS: { + code: AuthErrorCode.PASSWORD_DOES_NOT_MEET_REQUIREMENTS, + message: 'The password does not meet the requirements.', + }, INVALID_PHONE_NUMBER: { code: AuthErrorCode.INVALID_PHONE_NUMBER, message: 'The phone number must be a non-empty E.164 standard compliant identifier string.', @@ -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..24a1259e50 100644 --- a/test/unit/utils/error.spec.ts +++ b/test/unit/utils/error.spec.ts @@ -138,6 +138,11 @@ 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'); + }); + 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'); From 26cff32f3896dd32e6f4774aad9b8bd9a64901d3 Mon Sep 17 00:00:00 2001 From: Sean Li <22557931+sean0407@users.noreply.github.com> Date: Tue, 20 Oct 2026 06:28:44 +0800 Subject: [PATCH 2/2] test(auth): apply password policy review feedback --- src/auth/error.ts | 10 +++++----- test/unit/utils/error.spec.ts | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/auth/error.ts b/src/auth/error.ts index 2451627576..9a259ea5e5 100644 --- a/src/auth/error.ts +++ b/src/auth/error.ts @@ -64,7 +64,6 @@ export const AuthErrorCode = { INVALID_PASSWORD: 'invalid-password', INVALID_PASSWORD_HASH: 'invalid-password-hash', INVALID_PASSWORD_SALT: 'invalid-password-salt', - PASSWORD_DOES_NOT_MEET_REQUIREMENTS: 'password-does-not-meet-requirements', INVALID_PHONE_NUMBER: 'invalid-phone-number', INVALID_PHOTO_URL: 'invalid-photo-url', INVALID_PROJECT_ID: 'invalid-project-id', @@ -96,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', @@ -298,10 +298,6 @@ export const authClientErrorCode: { readonly [K in keyof typeof AuthErrorCode]: code: AuthErrorCode.INVALID_PASSWORD_SALT, message: 'The password salt must be a valid byte buffer.', }, - PASSWORD_DOES_NOT_MEET_REQUIREMENTS: { - code: AuthErrorCode.PASSWORD_DOES_NOT_MEET_REQUIREMENTS, - message: 'The password does not meet the requirements.', - }, INVALID_PHONE_NUMBER: { code: AuthErrorCode.INVALID_PHONE_NUMBER, message: 'The phone number must be a non-empty E.164 standard compliant identifier string.', @@ -428,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.', diff --git a/test/unit/utils/error.spec.ts b/test/unit/utils/error.spec.ts index 24a1259e50..cf06f93c51 100644 --- a/test/unit/utils/error.spec.ts +++ b/test/unit/utils/error.spec.ts @@ -141,6 +141,7 @@ describe('FirebaseAuthError', () => { 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', () => {