Skip to content

Commit 3b48235

Browse files
fix(auth): make MFA uid optional for updateUser operations (#1278)
* fix(auth): make MFA uid optional for updateUser operations MFA `uid` should be optional for `updateUser` operations. When not specified, the backend will provision a `uid` for the enrolled second factor. Fixes #1276
1 parent fd23ad0 commit 3b48235

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/auth/auth-api-request.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,8 @@ class AuthHttpClient extends AuthorizedHttpClient {
257257
* an error is thrown.
258258
*
259259
* @param request The AuthFactorInfo request object.
260-
* @param writeOperationType The write operation type.
261260
*/
262-
function validateAuthFactorInfo(request: AuthFactorInfo, writeOperationType: WriteOperationType): void {
261+
function validateAuthFactorInfo(request: AuthFactorInfo): void {
263262
const validKeys = {
264263
mfaEnrollmentId: true,
265264
displayName: true,
@@ -275,8 +274,8 @@ function validateAuthFactorInfo(request: AuthFactorInfo, writeOperationType: Wri
275274
// No enrollment ID is available for signupNewUser. Use another identifier.
276275
const authFactorInfoIdentifier =
277276
request.mfaEnrollmentId || request.phoneInfo || JSON.stringify(request);
278-
const uidRequired = writeOperationType !== WriteOperationType.Create;
279-
if ((typeof request.mfaEnrollmentId !== 'undefined' || uidRequired) &&
277+
// Enrollment uid may or may not be specified for update operations.
278+
if (typeof request.mfaEnrollmentId !== 'undefined' &&
280279
!validator.isNonEmptyString(request.mfaEnrollmentId)) {
281280
throw new FirebaseAuthError(
282281
AuthClientErrorCode.INVALID_UID,
@@ -573,7 +572,7 @@ function validateCreateEditRequest(request: any, writeOperationType: WriteOperat
573572
throw new FirebaseAuthError(AuthClientErrorCode.INVALID_ENROLLED_FACTORS);
574573
}
575574
enrollments.forEach((authFactorInfoEntry: AuthFactorInfo) => {
576-
validateAuthFactorInfo(authFactorInfoEntry, writeOperationType);
575+
validateAuthFactorInfo(authFactorInfoEntry);
577576
});
578577
}
579578
}

test/unit/auth/auth-api-request.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,11 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
20712071
phoneNumber: '+16505551000',
20722072
factorId: 'phone',
20732073
} as UpdateMultiFactorInfoRequest,
2074+
{
2075+
// No error should be thrown when no uid is specified.
2076+
phoneNumber: '+16505551234',
2077+
factorId: 'phone',
2078+
} as UpdateMultiFactorInfoRequest,
20742079
],
20752080
},
20762081
};
@@ -2096,6 +2101,9 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
20962101
mfaEnrollmentId: 'enrolledSecondFactor2',
20972102
phoneInfo: '+16505551000',
20982103
},
2104+
{
2105+
phoneInfo: '+16505551234',
2106+
},
20992107
],
21002108
},
21012109
};

0 commit comments

Comments
 (0)