Skip to content

fix(auth): make MFA uid optional for updateUser operations #1278

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
May 18, 2021
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
9 changes: 4 additions & 5 deletions src/auth/auth-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,8 @@ class AuthHttpClient extends AuthorizedHttpClient {
* an error is thrown.
*
* @param request The AuthFactorInfo request object.
* @param writeOperationType The write operation type.
*/
function validateAuthFactorInfo(request: AuthFactorInfo, writeOperationType: WriteOperationType): void {
function validateAuthFactorInfo(request: AuthFactorInfo): void {
const validKeys = {
mfaEnrollmentId: true,
displayName: true,
Expand All @@ -275,8 +274,8 @@ function validateAuthFactorInfo(request: AuthFactorInfo, writeOperationType: Wri
// No enrollment ID is available for signupNewUser. Use another identifier.
const authFactorInfoIdentifier =
request.mfaEnrollmentId || request.phoneInfo || JSON.stringify(request);
const uidRequired = writeOperationType !== WriteOperationType.Create;
if ((typeof request.mfaEnrollmentId !== 'undefined' || uidRequired) &&
// Enrollment uid may or may not be specified for update operations.
if (typeof request.mfaEnrollmentId !== 'undefined' &&
!validator.isNonEmptyString(request.mfaEnrollmentId)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_UID,
Expand Down Expand Up @@ -573,7 +572,7 @@ function validateCreateEditRequest(request: any, writeOperationType: WriteOperat
throw new FirebaseAuthError(AuthClientErrorCode.INVALID_ENROLLED_FACTORS);
}
enrollments.forEach((authFactorInfoEntry: AuthFactorInfo) => {
validateAuthFactorInfo(authFactorInfoEntry, writeOperationType);
validateAuthFactorInfo(authFactorInfoEntry);
});
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/unit/auth/auth-api-request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,11 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
phoneNumber: '+16505551000',
factorId: 'phone',
} as UpdateMultiFactorInfoRequest,
{
// No error should be thrown when no uid is specified.
phoneNumber: '+16505551234',
factorId: 'phone',
} as UpdateMultiFactorInfoRequest,
],
},
};
Expand All @@ -2096,6 +2101,9 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
mfaEnrollmentId: 'enrolledSecondFactor2',
phoneInfo: '+16505551000',
},
{
phoneInfo: '+16505551234',
},
],
},
};
Expand Down