diff options
author | Catalan Lover <48515417+FSG-Cat@users.noreply.github.com> | 2022-08-23 23:50:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-23 23:50:01 +0200 |
commit | d63451b3fe6c0c6ab175adec82361834bb3633f5 (patch) | |
tree | b738ee25bf9819300e1802ba9a8e2813e9dc2588 /src/api/routes/auth/mfa/totp.ts | |
parent | Merge pull request #1 from FSG-Cat/FSG-Cat-patch-1 (diff) | |
parent | Check Captcha (diff) | |
download | server-d63451b3fe6c0c6ab175adec82361834bb3633f5.tar.xz |
Merge branch 'fosscord:staging' into Bug-Report-Template
Diffstat (limited to 'src/api/routes/auth/mfa/totp.ts')
-rw-r--r-- | src/api/routes/auth/mfa/totp.ts | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/api/routes/auth/mfa/totp.ts b/src/api/routes/auth/mfa/totp.ts index 421dbafa..9938569e 100644 --- a/src/api/routes/auth/mfa/totp.ts +++ b/src/api/routes/auth/mfa/totp.ts @@ -1,8 +1,8 @@ -import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; -import { BackupCode, FieldErrors, generateToken, TotpSchema, User } from "@fosscord/util"; -import { verifyToken } from "node-2fa"; +import { BackupCode, generateToken, TotpSchema, User } from "@fosscord/util"; +import { Request, Response, Router } from "express"; import { HTTPError } from "lambert-server"; +import { verifyToken } from "node-2fa"; const router = Router(); router.post("/", route({ body: "TotpSchema" }), async (req: Request, res: Response) => { @@ -10,23 +10,17 @@ router.post("/", route({ body: "TotpSchema" }), async (req: Request, res: Respon const user = await User.findOneOrFail({ where: { - totp_last_ticket: ticket, + totp_last_ticket: ticket }, - select: [ - "id", - "totp_secret", - "settings", - ], + select: ["id", "totp_secret", "settings"] }); const backup = await BackupCode.findOne({ where: { code: code, expired: false, consumed: false, user: { id: user.id } } }); if (!backup) { const ret = verifyToken(user.totp_secret!, code); - if (!ret || ret.delta != 0) - throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008); - } - else { + if (!ret || ret.delta != 0) throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008); + } else { backup.consumed = true; await backup.save(); } @@ -35,7 +29,7 @@ router.post("/", route({ body: "TotpSchema" }), async (req: Request, res: Respon return res.json({ token: await generateToken(user.id), - user_settings: user.settings, + user_settings: user.settings }); }); |