auth cleanup

This commit is contained in:
2026-07-04 00:28:31 -05:00
parent 4149e13337
commit 1e43be14bd
4 changed files with 21 additions and 22 deletions
+1 -2
View File
@@ -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();
};
+1 -2
View File
@@ -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();
};
-9
View File
@@ -1,9 +0,0 @@
import { Request, Response, NextFunction } from "express";
export function validateCall(
req: Request,
res: Response,
next: NextFunction
) {
next();
};
+19 -9
View File
@@ -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)