refactor: edit tailwindcss classes and change code formatting, therefore added .prettierrc file

fix: frontend bug where the passwords won't be checked when the password is changed
This commit is contained in:
2026-07-08 14:56:43 +02:00
parent 9c50c3f300
commit 6be34c93aa
36 changed files with 1280 additions and 1145 deletions
+23 -19
View File
@@ -1,36 +1,40 @@
import type {NextFunction, Request, Response} from "express";
import {type JWTPayload, jwtVerify, SignJWT} from "jose";
import type { NextFunction, Request, Response } from "express";
import { type JWTPayload, jwtVerify, SignJWT } from "jose";
import env from "dotenv";
env.config();
const secret = new TextEncoder().encode(process.env.SECRET_KEY);
export type AuthTokenPayload = JWTPayload & {
username: string;
username: string;
};
declare module "express-serve-static-core" {
interface Request {
user?: AuthTokenPayload;
}
interface Request {
user?: AuthTokenPayload;
}
}
export async function generateToken(payload: AuthTokenPayload) {
return await new SignJWT(payload)
.setProtectedHeader({alg: "HS256"})
.setIssuedAt()
.setExpirationTime("24h")
.sign(secret);
return await new SignJWT(payload)
.setProtectedHeader({ alg: "HS256" })
.setIssuedAt()
.setExpirationTime("24h")
.sign(secret);
}
export async function authenticate(req: Request, res: Response, next: NextFunction) {
const authHeader = req.headers["authorization"];
const token = authHeader && authHeader.split(" ")[1];
export async function authenticate(
req: Request,
res: Response,
next: NextFunction,
) {
const authHeader = req.headers["authorization"];
const token = authHeader && authHeader.split(" ")[1];
if (token == null) return res.sendStatus(401);
if (token == null) return res.sendStatus(401);
const {payload} = await jwtVerify<AuthTokenPayload>(token, secret);
req.user = payload;
const { payload } = await jwtVerify<AuthTokenPayload>(token, secret);
req.user = payload;
next();
}
next();
}