summary refs log tree commit diff
path: root/api/src/routes/auth/login.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-21 22:52:30 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-21 22:52:30 +0200
commitabdce76df4b6aa3a063b496e6c0575c54e9fa397 (patch)
treec135233da7c327eeb52f143a2632f5d5bd4b65b5 /api/src/routes/auth/login.ts
parent:bug: fix unittests (diff)
downloadserver-abdce76df4b6aa3a063b496e6c0575c54e9fa397.tar.xz
:sparkles: generate openapi documentation
Diffstat (limited to 'api/src/routes/auth/login.ts')
-rw-r--r--api/src/routes/auth/login.ts23
1 files changed, 1 insertions, 22 deletions
diff --git a/api/src/routes/auth/login.ts b/api/src/routes/auth/login.ts
index f672658a..ff04f8aa 100644
--- a/api/src/routes/auth/login.ts
+++ b/api/src/routes/auth/login.ts
@@ -1,9 +1,7 @@
 import { Request, Response, Router } from "express";
 import { FieldErrors, route } from "@fosscord/api";
 import bcrypt from "bcrypt";
-import jwt from "jsonwebtoken";
-import { Config, User } from "@fosscord/util";
-import { adjustEmail } from "./register";
+import { Config, User, generateToken, adjustEmail } from "@fosscord/util";
 
 const router: Router = Router();
 export default router;
@@ -68,25 +66,6 @@ router.post("/", route({ body: "LoginSchema" }), async (req: Request, res: Respo
 	res.json({ token, settings: user.settings });
 });
 
-export async function generateToken(id: string) {
-	const iat = Math.floor(Date.now() / 1000);
-	const algorithm = "HS256";
-
-	return new Promise((res, rej) => {
-		jwt.sign(
-			{ id: id, iat },
-			Config.get().security.jwtSecret,
-			{
-				algorithm
-			},
-			(err, token) => {
-				if (err) return rej(err);
-				return res(token);
-			}
-		);
-	});
-}
-
 /**
  * POST /auth/login
  * @argument { login: "email@gmail.com", password: "cleartextpassword", undelete: false, captcha_key: null, login_source: null, gift_code_sku_id: null, }