mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-10 12:28:56 +00:00
chores: clean login
This commit is contained in:
@@ -204,20 +204,16 @@ export const login2 = async (req: Request, res: Response) => {
|
|||||||
* @param res
|
* @param res
|
||||||
*/
|
*/
|
||||||
export const sendMfaToken = async (req: Request, res: Response) => {
|
export const sendMfaToken = async (req: Request, res: Response) => {
|
||||||
const {
|
|
||||||
body: { email }
|
|
||||||
} = await validateRequest(reqValidator.SendMfaTokenV2, req);
|
|
||||||
|
|
||||||
const code = await TokenService.createToken({
|
const code = await TokenService.createToken({
|
||||||
type: TOKEN_EMAIL_MFA,
|
type: TOKEN_EMAIL_MFA,
|
||||||
email
|
email: req.user.email
|
||||||
});
|
});
|
||||||
|
|
||||||
// send MFA code [code] to [email]
|
// send MFA code [code] to [email]
|
||||||
await sendMail({
|
await sendMail({
|
||||||
template: "emailMfa.handlebars",
|
template: "emailMfa.handlebars",
|
||||||
subjectLine: "Infisical MFA code",
|
subjectLine: "Infisical MFA code",
|
||||||
recipients: [email],
|
recipients: [req.user.email],
|
||||||
substitutions: {
|
substitutions: {
|
||||||
code
|
code
|
||||||
}
|
}
|
||||||
@@ -236,17 +232,17 @@ export const sendMfaToken = async (req: Request, res: Response) => {
|
|||||||
*/
|
*/
|
||||||
export const verifyMfaToken = async (req: Request, res: Response) => {
|
export const verifyMfaToken = async (req: Request, res: Response) => {
|
||||||
const {
|
const {
|
||||||
body: { email, mfaToken }
|
body: { mfaToken }
|
||||||
} = await validateRequest(reqValidator.VerifyMfaTokenV2, req);
|
} = await validateRequest(reqValidator.VerifyMfaTokenV2, req);
|
||||||
|
|
||||||
await TokenService.validateToken({
|
await TokenService.validateToken({
|
||||||
type: TOKEN_EMAIL_MFA,
|
type: TOKEN_EMAIL_MFA,
|
||||||
email,
|
email: req.user.email,
|
||||||
token: mfaToken
|
token: mfaToken
|
||||||
});
|
});
|
||||||
|
|
||||||
const user = await User.findOne({
|
const user = await User.findOne({
|
||||||
email
|
email: req.user.email
|
||||||
}).select(
|
}).select(
|
||||||
"+salt +verifier +encryptionVersion +protectedKey +protectedKeyIV +protectedKeyTag +publicKey +encryptedPrivateKey +iv +tag +devices"
|
"+salt +verifier +encryptionVersion +protectedKey +protectedKeyIV +protectedKeyTag +publicKey +encryptedPrivateKey +iv +tag +devices"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ router.post(
|
|||||||
);
|
);
|
||||||
|
|
||||||
//remove above ones after depreciation
|
//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);
|
router.post("/mfa/verify", authLimiter, requireMfaAuth, authController.verifyMfaToken);
|
||||||
|
|
||||||
|
|||||||
@@ -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({
|
export const VerifyMfaTokenV2 = z.object({
|
||||||
body: z.object({
|
body: z.object({
|
||||||
email: z.string().email().trim(),
|
|
||||||
mfaToken: z.string().trim()
|
mfaToken: z.string().trim()
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user