diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2023-01-20 18:10:47 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-20 18:10:47 +1100 |
commit | 084dc0be08555891cad4c2bb984822a62ec5ec9f (patch) | |
tree | ed2ca0fafefa2224ae32761f955f63935422a97d /src/api/routes/auth | |
parent | fix: route file regex (#956) (diff) | |
download | server-084dc0be08555891cad4c2bb984822a62ec5ec9f.tar.xz |
Add ESLint (#941)
* Add eslint, switch to lint-staged for precommit * Fix all ESLint errors * Update GH workflow to check prettier and eslint
Diffstat (limited to 'src/api/routes/auth')
-rw-r--r-- | src/api/routes/auth/generate-registration-tokens.ts | 2 | ||||
-rw-r--r-- | src/api/routes/auth/login.ts | 2 | ||||
-rw-r--r-- | src/api/routes/auth/mfa/totp.ts | 6 | ||||
-rw-r--r-- | src/api/routes/auth/register.ts | 10 |
4 files changed, 10 insertions, 10 deletions
diff --git a/src/api/routes/auth/generate-registration-tokens.ts b/src/api/routes/auth/generate-registration-tokens.ts index 64e3b0a6..c79d2a59 100644 --- a/src/api/routes/auth/generate-registration-tokens.ts +++ b/src/api/routes/auth/generate-registration-tokens.ts @@ -32,7 +32,7 @@ router.get( ? parseInt(req.query.length as string) : 255; - let tokens: ValidRegistrationToken[] = []; + const tokens: ValidRegistrationToken[] = []; for (let i = 0; i < count; i++) { const token = ValidRegistrationToken.create({ diff --git a/src/api/routes/auth/login.ts b/src/api/routes/auth/login.ts index 5f1b7a14..4d367546 100644 --- a/src/api/routes/auth/login.ts +++ b/src/api/routes/auth/login.ts @@ -74,7 +74,7 @@ router.post( "totp_secret", "mfa_enabled", ], - }).catch((e) => { + }).catch(() => { throw FieldErrors({ login: { message: req.t("auth:login.INVALID_LOGIN"), diff --git a/src/api/routes/auth/mfa/totp.ts b/src/api/routes/auth/mfa/totp.ts index 42485535..65cdd397 100644 --- a/src/api/routes/auth/mfa/totp.ts +++ b/src/api/routes/auth/mfa/totp.ts @@ -27,8 +27,8 @@ router.post( "/", route({ body: "TotpSchema" }), async (req: Request, res: Response) => { - const { code, ticket, gift_code_sku_id, login_source } = - req.body as TotpSchema; + // const { code, ticket, gift_code_sku_id, login_source } = + const { code, ticket } = req.body as TotpSchema; const user = await User.findOneOrFail({ where: { @@ -47,7 +47,7 @@ router.post( }); if (!backup) { - const ret = verifyToken(user.totp_secret!, code); + const ret = verifyToken(user.totp_secret || "", code); if (!ret || ret.delta != 0) throw new HTTPError( req.t("auth:login.INVALID_TOTP_CODE"), diff --git a/src/api/routes/auth/register.ts b/src/api/routes/auth/register.ts index b98f17c5..0bf8efae 100644 --- a/src/api/routes/auth/register.ts +++ b/src/api/routes/auth/register.ts @@ -36,7 +36,7 @@ import { } from "@fosscord/api"; import bcrypt from "bcrypt"; import { HTTPError } from "lambert-server"; -import { LessThan, MoreThan } from "typeorm"; +import { MoreThan } from "typeorm"; const router: Router = Router(); @@ -53,12 +53,12 @@ router.post( let regTokenUsed = false; if (req.get("Referrer") && req.get("Referrer")?.includes("token=")) { // eg theyre on https://staging.fosscord.com/register?token=whatever - const token = req.get("Referrer")!.split("token=")[1].split("&")[0]; + const token = req.get("Referrer")?.split("token=")[1].split("&")[0]; if (token) { - const regToken = await ValidRegistrationToken.findOne({ + const regToken = await ValidRegistrationToken.findOneOrFail({ where: { token, expires_at: MoreThan(new Date()) }, }); - await ValidRegistrationToken.delete({ token }); + await regToken.remove(); regTokenUsed = true; console.log( `[REGISTER] Registration token ${token} used for registration!`, @@ -71,7 +71,7 @@ router.post( } // email will be slightly modified version of the user supplied email -> e.g. protection against GMail Trick - let email = adjustEmail(body.email); + const email = adjustEmail(body.email); // check if registration is allowed if (!regTokenUsed && !register.allowNewRegistration) { |