Skip to content

Commit

Permalink
chores: clean login
Browse files Browse the repository at this point in the history
  • Loading branch information
maidul98 committed Dec 2, 2023
1 parent 735cf09 commit 4b41664
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
14 changes: 5 additions & 9 deletions backend/src/controllers/v2/authController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,16 @@ export const login2 = async (req: Request, res: Response) => {
* @param res
*/
export const sendMfaToken = async (req: Request, res: Response) => {
const {
body: { email }
} = await validateRequest(reqValidator.SendMfaTokenV2, req);

const code = await TokenService.createToken({
type: TOKEN_EMAIL_MFA,
email
email: req.user.email
});

// send MFA code [code] to [email]
await sendMail({
template: "emailMfa.handlebars",
subjectLine: "Infisical MFA code",
recipients: [email],
recipients: [req.user.email],
substitutions: {
code
}
Expand All @@ -236,17 +232,17 @@ export const sendMfaToken = async (req: Request, res: Response) => {
*/
export const verifyMfaToken = async (req: Request, res: Response) => {
const {
body: { email, mfaToken }
body: { mfaToken }
} = await validateRequest(reqValidator.VerifyMfaTokenV2, req);

await TokenService.validateToken({
type: TOKEN_EMAIL_MFA,
email,
email: req.user.email,
token: mfaToken
});

const user = await User.findOne({
email
email: req.user.email
}).select(
"+salt +verifier +encryptionVersion +protectedKey +protectedKeyIV +protectedKeyTag +publicKey +encryptedPrivateKey +iv +tag +devices"
);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/v2/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ router.post(
);

//remove above ones after depreciation
router.post("/mfa/send", authLimiter, authController.sendMfaToken);
router.post("/mfa/send", authLimiter, requireMfaAuth, authController.sendMfaToken);

router.post("/mfa/verify", authLimiter, requireMfaAuth, authController.verifyMfaToken);

Expand Down
7 changes: 0 additions & 7 deletions backend/src/validation/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,8 @@ export const ResetPasswordV1 = z.object({
})
});

export const SendMfaTokenV2 = z.object({
body: z.object({
email: z.string().email().trim()
})
});

export const VerifyMfaTokenV2 = z.object({
body: z.object({
email: z.string().email().trim(),
mfaToken: z.string().trim()
})
});
Expand Down

0 comments on commit 4b41664

Please sign in to comment.