Skip to content
Snippets Groups Projects
Commit ff85a180 authored by Bernard Roland (Student Com20)'s avatar Bernard Roland (Student Com20)
Browse files

Invalid tokens are now allowed for unprotected routes

parent d4fef314
No related branches found
No related tags found
No related merge requests found
...@@ -109,7 +109,7 @@ auth.get("/extend", async function (req, res) { ...@@ -109,7 +109,7 @@ auth.get("/extend", async function (req, res) {
} }
}); });
export async function tokenVerification(req: Request, res: Response, next: NextFunction) { export async function tokenVerification(req: Request, _res: Response, next: NextFunction) {
const header = req.headers?.authorization; const header = req.headers?.authorization;
let token: string | null = null; let token: string | null = null;
if (header) { if (header) {
...@@ -124,13 +124,10 @@ export async function tokenVerification(req: Request, res: Response, next: NextF ...@@ -124,13 +124,10 @@ export async function tokenVerification(req: Request, res: Response, next: NextF
try { try {
const decoded = await asyncify(verify, token, await getPublicKey(), { algorithms: ["ES384"] }); const decoded = await asyncify(verify, token, await getPublicKey(), { algorithms: ["ES384"] });
req.body.token = decoded; req.body.token = decoded;
next();
} catch (err) { } catch (err) {
res.status(403).json({ delete req.body.token;
status: 'error',
message: 'authentication failed',
});
} }
next();
} else { } else {
next(); next();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment