Skip to content

Commit

Permalink
fix(authentication): twoFaMethod missing param in admin routes (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
SotiriaSte authored Sep 12, 2022
1 parent f92bb7b commit 4b504b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/authentication/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class AdminHandlers {
isVerified: ConduitBoolean.Optional,
hasTwoFA: ConduitBoolean.Optional,
phoneNumber: ConduitString.Optional,
twoFaMethod: ConduitString.Optional,
},
},
new ConduitRouteReturnDefinition('PatchUser', userFields),
Expand Down
10 changes: 9 additions & 1 deletion modules/authentication/src/admin/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export class UserAdmin {
}

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

const user: User | null = await User.getInstance().findOne({ _id: id });
if (isNil(user)) {
Expand All @@ -85,12 +86,19 @@ 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',
);
}

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

const res: User | null = await User.getInstance().findByIdAndUpdate(user._id, query);
Expand Down
2 changes: 1 addition & 1 deletion modules/sms/src/providers/twilio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class TwilioProvider implements ISmsProvider {
});

if (!verification) {
return Promise.reject(Error('could not send verication code'));
return Promise.reject(Error('could not send verification code'));
}

return Promise.resolve(verification.sid);
Expand Down

0 comments on commit 4b504b9

Please sign in to comment.