Skip to content

Commit

Permalink
fix(authentication): admin patch user twoFaMethod (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
SotiriaSte committed Nov 30, 2022
1 parent 741c128 commit 556c402
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions modules/authentication/src/admin/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ export class UserAdmin {
}

async patchUser(call: ParsedRouterRequest): Promise<UnparsedRouterResponse> {
const { id, email, isVerified, hasTwoFA, phoneNumber, twoFaMethod } =
call.request.params;
const { id, email, isVerified, hasTwoFA, phoneNumber } = call.request.params;

const user: User | null = await User.getInstance().findOne({ _id: id });
if (isNil(user)) {
Expand All @@ -86,19 +85,16 @@ export class UserAdmin {
'Can not enable 2fa without a phone number',
);
}
if (twoFaMethod !== 'phone') {
throw new GrpcError(
status.INVALID_ARGUMENT,
'Can not enable 2fa with other method than phone',
);
let twoFaMethod: string | undefined;
if (hasTwoFA) {
twoFaMethod = user.twoFaMethod ?? 'phone';
}

const query = {
email: email ?? user.email,
isVerified: isVerified ?? user.isVerified,
hasTwoFA: hasTwoFA ?? user.hasTwoFA,
phoneNumber: phoneNumber ?? user.phoneNumber,
twoFaMethod: twoFaMethod ?? user.twoFaMethod,
twoFaMethod: twoFaMethod,
};

const res: User | null = await User.getInstance().findByIdAndUpdate(user._id, query);
Expand Down

0 comments on commit 556c402

Please sign in to comment.