diff --git a/backend/src/middleware/loadJWT.ts b/backend/src/middleware/loadJWT.ts index fe37c8f..083a026 100644 --- a/backend/src/middleware/loadJWT.ts +++ b/backend/src/middleware/loadJWT.ts @@ -2,7 +2,6 @@ import { Request, Response, NextFunction } from "express"; import JsonWebToken from '../types/JsonWebToken.ts'; import { verifySignature, decodeJWT } from '../helpers/jwt.ts'; import { refreshJWT } from "./refreshJWT.ts"; -import { validateCall } from "./validateCall.ts"; export function loadJWT( req: Request, @@ -68,6 +67,6 @@ export function loadJWT( } } - return validateCall(req, res, next); + return next(); }; diff --git a/backend/src/middleware/refreshJWT.ts b/backend/src/middleware/refreshJWT.ts index 9af7c30..945beee 100644 --- a/backend/src/middleware/refreshJWT.ts +++ b/backend/src/middleware/refreshJWT.ts @@ -1,5 +1,4 @@ import { Request, Response, NextFunction } from "express"; -import { validateCall } from "./validateCall.ts"; import { drizzle } from 'drizzle-orm/node-postgres'; import { eq } from 'drizzle-orm'; import { users } from '../db/schema.ts'; @@ -66,5 +65,5 @@ export async function refreshJWT( const parsedJWT = decodeJWT(jwt); req.jwt = parsedJWT; - return validateCall(req, res, next); + return next(); }; diff --git a/backend/src/middleware/validateCall.ts b/backend/src/middleware/validateCall.ts deleted file mode 100644 index 7a1c93e..0000000 --- a/backend/src/middleware/validateCall.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Request, Response, NextFunction } from "express"; - -export function validateCall( - req: Request, - res: Response, - next: NextFunction -) { - next(); -}; diff --git a/backend/src/routes/auth.ts b/backend/src/routes/auth.ts index 7a37e5f..e3f333e 100644 --- a/backend/src/routes/auth.ts +++ b/backend/src/routes/auth.ts @@ -51,19 +51,29 @@ authRouter.post("/signup", async (req: Request, res: Response) => { .update(`${presalt}${password}${postsalt}`) .digest("base64url"); - await db - .insert(users) - .values({ - display_name: display_name, - username: username, - hashed_password: hashedPassword, - permissions: 44 - }); + try { + await db + .insert(users) + .values({ + display_name: display_name, + username: username, + hashed_password: hashedPassword, + permissions: 44 + }); + } catch (err: any) { + if (err.cause.code === "23505") { + return res.status(409).json({ + error: "Username already exists" + }); + } + + throw err; + } loginUser(username, password, res); }); -// because it write the response, has to be last step +// because it writes to the response, has to be last step async function loginUser(username: string, password: string, res: Response) { const hashedPassword = crypto .createHmac('sha256', hashSecret)