Skip to content

fixing error code for missing password #7171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 30, 2023
Merged
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
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