Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/auth/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.',
Expand Down Expand Up @@ -605,6 +610,8 @@ const AUTH_SERVER_TO_CLIENT_CODE: Record<string, keyof typeof AuthErrorCode> = {
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.
Expand Down
6 changes: 6 additions & 0 deletions test/unit/utils/error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
});
Comment on lines +141 to +145

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To ensure consistency with other test cases in this file, we should also assert that the mapped error message is correct.

Suggested change
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 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');
Expand Down
Loading