diff --git a/packages/auth/src/api/authentication/email_and_password.test.ts b/packages/auth/src/api/authentication/email_and_password.test.ts index f67982c1246..e58e5f4b293 100644 --- a/packages/auth/src/api/authentication/email_and_password.test.ts +++ b/packages/auth/src/api/authentication/email_and_password.test.ts @@ -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, { @@ -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', () => { diff --git a/packages/auth/src/api/errors.ts b/packages/auth/src/api/errors.ts index c91d46dbe46..b106dfb17c2 100644 --- a/packages/auth/src/api/errors.ts +++ b/packages/auth/src/api/errors.ts @@ -134,7 +134,7 @@ export const SERVER_ERROR_MAP: Partial> = { // 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, diff --git a/packages/auth/src/core/errors.ts b/packages/auth/src/core/errors.ts index 17656a0438c..dbd62fb65ef 100644 --- a/packages/auth/src/core/errors.ts +++ b/packages/auth/src/core/errors.ts @@ -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', @@ -267,6 +268,7 @@ function _debugErrorMap(): ErrorMap { '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]: