Skip to content

Commit

Permalink
fixing error code for missing password (#7171)
Browse files Browse the repository at this point in the history
* fixing error code for missing password

* fixed formatting errors
  • Loading branch information
bhparijat committed Mar 30, 2023
1 parent 81cb20a commit f8a2c58
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
27 changes: 26 additions & 1 deletion packages/auth/src/api/authentication/email_and_password.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('api/authentication/signInWithPassword', () => {
);
});

it('should handle errors', async () => {
it('should handle errors for invalid password', async () => {
const mock = mockEndpoint(
Endpoint.SIGN_IN_WITH_PASSWORD,
{
Expand All @@ -99,6 +99,31 @@ describe('api/authentication/signInWithPassword', () => {
);
expect(mock.calls[0].request).to.eql(request);
});

it('should handle errors for missing password', async () => {
request.password = '';
const mock = mockEndpoint(
Endpoint.SIGN_IN_WITH_PASSWORD,
{
error: {
code: 400,
message: ServerError.MISSING_PASSWORD,
errors: [
{
message: ServerError.MISSING_PASSWORD
}
]
}
},
400
);

await expect(signInWithPassword(auth, request)).to.be.rejectedWith(
FirebaseError,
'Firebase: A non-empty password must be provided (auth/missing-password).'
);
expect(mock.calls[0].request).to.eql(request);
});
});

describe('api/authentication/sendEmailVerification', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/api/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const SERVER_ERROR_MAP: Partial<ServerErrorMap<ServerError>> = {
// Sign in with email and password errors (some apply to sign up too).
[ServerError.INVALID_PASSWORD]: AuthErrorCode.INVALID_PASSWORD,
// This can only happen if the SDK sends a bad request.
[ServerError.MISSING_PASSWORD]: AuthErrorCode.INTERNAL_ERROR,
[ServerError.MISSING_PASSWORD]: AuthErrorCode.MISSING_PASSWORD,

// Sign up with email and password errors.
[ServerError.EMAIL_EXISTS]: AuthErrorCode.EMAIL_EXISTS,
Expand Down
2 changes: 2 additions & 0 deletions packages/auth/src/core/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const enum AuthErrorCode {
MISSING_MFA_INFO = 'missing-multi-factor-info',
MISSING_MFA_SESSION = 'missing-multi-factor-session',
MISSING_PHONE_NUMBER = 'missing-phone-number',
MISSING_PASSWORD = 'missing-password',
MISSING_SESSION_INFO = 'missing-verification-id',
MODULE_DESTROYED = 'app-deleted',
NEED_CONFIRMATION = 'account-exists-with-different-credential',
Expand Down Expand Up @@ -267,6 +268,7 @@ function _debugErrorMap(): ErrorMap<AuthErrorCode> {
'The request does not contain a valid nonce. This can occur if the ' +
'SHA-256 hash of the provided raw nonce does not match the hashed nonce ' +
'in the ID token payload.',
[AuthErrorCode.MISSING_PASSWORD]: 'A non-empty password must be provided',
[AuthErrorCode.MISSING_MFA_INFO]:
'No second factor identifier is provided.',
[AuthErrorCode.MISSING_MFA_SESSION]:
Expand Down

0 comments on commit f8a2c58

Please sign in to comment.