Skip to content

Commit f8a2c58

Browse files
authored
fixing error code for missing password (#7171)
* fixing error code for missing password * fixed formatting errors
1 parent 81cb20a commit f8a2c58

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

packages/auth/src/api/authentication/email_and_password.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('api/authentication/signInWithPassword', () => {
7676
);
7777
});
7878

79-
it('should handle errors', async () => {
79+
it('should handle errors for invalid password', async () => {
8080
const mock = mockEndpoint(
8181
Endpoint.SIGN_IN_WITH_PASSWORD,
8282
{
@@ -99,6 +99,31 @@ describe('api/authentication/signInWithPassword', () => {
9999
);
100100
expect(mock.calls[0].request).to.eql(request);
101101
});
102+
103+
it('should handle errors for missing password', async () => {
104+
request.password = '';
105+
const mock = mockEndpoint(
106+
Endpoint.SIGN_IN_WITH_PASSWORD,
107+
{
108+
error: {
109+
code: 400,
110+
message: ServerError.MISSING_PASSWORD,
111+
errors: [
112+
{
113+
message: ServerError.MISSING_PASSWORD
114+
}
115+
]
116+
}
117+
},
118+
400
119+
);
120+
121+
await expect(signInWithPassword(auth, request)).to.be.rejectedWith(
122+
FirebaseError,
123+
'Firebase: A non-empty password must be provided (auth/missing-password).'
124+
);
125+
expect(mock.calls[0].request).to.eql(request);
126+
});
102127
});
103128

104129
describe('api/authentication/sendEmailVerification', () => {

packages/auth/src/api/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export const SERVER_ERROR_MAP: Partial<ServerErrorMap<ServerError>> = {
134134
// Sign in with email and password errors (some apply to sign up too).
135135
[ServerError.INVALID_PASSWORD]: AuthErrorCode.INVALID_PASSWORD,
136136
// This can only happen if the SDK sends a bad request.
137-
[ServerError.MISSING_PASSWORD]: AuthErrorCode.INTERNAL_ERROR,
137+
[ServerError.MISSING_PASSWORD]: AuthErrorCode.MISSING_PASSWORD,
138138

139139
// Sign up with email and password errors.
140140
[ServerError.EMAIL_EXISTS]: AuthErrorCode.EMAIL_EXISTS,

packages/auth/src/core/errors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export const enum AuthErrorCode {
8989
MISSING_MFA_INFO = 'missing-multi-factor-info',
9090
MISSING_MFA_SESSION = 'missing-multi-factor-session',
9191
MISSING_PHONE_NUMBER = 'missing-phone-number',
92+
MISSING_PASSWORD = 'missing-password',
9293
MISSING_SESSION_INFO = 'missing-verification-id',
9394
MODULE_DESTROYED = 'app-deleted',
9495
NEED_CONFIRMATION = 'account-exists-with-different-credential',
@@ -267,6 +268,7 @@ function _debugErrorMap(): ErrorMap<AuthErrorCode> {
267268
'The request does not contain a valid nonce. This can occur if the ' +
268269
'SHA-256 hash of the provided raw nonce does not match the hashed nonce ' +
269270
'in the ID token payload.',
271+
[AuthErrorCode.MISSING_PASSWORD]: 'A non-empty password must be provided',
270272
[AuthErrorCode.MISSING_MFA_INFO]:
271273
'No second factor identifier is provided.',
272274
[AuthErrorCode.MISSING_MFA_SESSION]:

0 commit comments

Comments
 (0)