Token will be sent in authorization via Bearer prefix

This commit is contained in:
StarAppeal
2024-11-21 10:20:32 +01:00
parent b510106de3
commit 0d85e78acc
+8 -7
View File
@@ -1,15 +1,16 @@
import { JwtAuthenticator } from "../../utils/jwtAuthenticator";
import { Request, Response, NextFunction } from "express";
import {JwtAuthenticator} from "../../utils/jwtAuthenticator";
import {Request, Response, NextFunction} from "express";
export function authenticateJwt(
req: Request,
res: Response,
next: NextFunction,
req: Request,
res: Response,
next: NextFunction,
) {
const token = req.headers["authorization"];
//remove Bearer from the beginning of the token
const token = req.headers["authorization"]?.slice("Bearer ".length);
const jwtAuthenticator = new JwtAuthenticator(
process.env.SECRET_KEY as string,
process.env.SECRET_KEY as string,
);
const decodedToken = jwtAuthenticator.verifyToken(token);
if (!decodedToken) {