summary refs log tree commit diff
path: root/src/api/routes/users/@me/mfa/codes-verification.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/routes/users/@me/mfa/codes-verification.ts')
-rw-r--r--src/api/routes/users/@me/mfa/codes-verification.ts82
1 files changed, 41 insertions, 41 deletions
diff --git a/src/api/routes/users/@me/mfa/codes-verification.ts b/src/api/routes/users/@me/mfa/codes-verification.ts

index c8995d83..4cc4c072 100644 --- a/src/api/routes/users/@me/mfa/codes-verification.ts +++ b/src/api/routes/users/@me/mfa/codes-verification.ts
@@ -24,52 +24,52 @@ import { CodesVerificationSchema } from "@spacebar/schemas"; const router = Router({ mergeParams: true }); router.post( - "/", - route({ - requestBody: "CodesVerificationSchema", - responses: { - 200: { - body: "APIBackupCodeArray", - }, - 400: { - body: "APIErrorResponse", - }, - 404: { - body: "APIErrorResponse", - }, - }, - }), - async (req: Request, res: Response) => { - // const { key, nonce, regenerate } = req.body as CodesVerificationSchema; - const { regenerate } = req.body as CodesVerificationSchema; + "/", + route({ + requestBody: "CodesVerificationSchema", + responses: { + 200: { + body: "APIBackupCodeArray", + }, + 400: { + body: "APIErrorResponse", + }, + 404: { + body: "APIErrorResponse", + }, + }, + }), + async (req: Request, res: Response) => { + // const { key, nonce, regenerate } = req.body as CodesVerificationSchema; + const { regenerate } = req.body as CodesVerificationSchema; - // TODO: We don't have email/etc etc, so can't send a verification code. - // Once that's done, this route can verify `key` + // TODO: We don't have email/etc etc, so can't send a verification code. + // Once that's done, this route can verify `key` - // const user = await User.findOneOrFail({ where: { id: req.user_id } }); - if ((await User.count({ where: { id: req.user_id } })) === 0) throw DiscordApiErrors.UNKNOWN_USER; + // const user = await User.findOneOrFail({ where: { id: req.user_id } }); + if ((await User.count({ where: { id: req.user_id } })) === 0) throw DiscordApiErrors.UNKNOWN_USER; - let codes: BackupCode[]; - if (regenerate) { - await BackupCode.update({ user: { id: req.user_id } }, { expired: true }); + let codes: BackupCode[]; + if (regenerate) { + await BackupCode.update({ user: { id: req.user_id } }, { expired: true }); - codes = generateMfaBackupCodes(req.user_id); - await Promise.all(codes.map((x) => x.save())); - } else { - codes = await BackupCode.find({ - where: { - user: { - id: req.user_id, - }, - expired: false, - }, - }); - } + codes = generateMfaBackupCodes(req.user_id); + await Promise.all(codes.map((x) => x.save())); + } else { + codes = await BackupCode.find({ + where: { + user: { + id: req.user_id, + }, + expired: false, + }, + }); + } - return res.json({ - backup_codes: codes.map((x) => ({ ...x, expired: undefined })), - }); - }, + return res.json({ + backup_codes: codes.map((x) => ({ ...x, expired: undefined })), + }); + }, ); export default router;