Token will be sent in authorization via Bearer prefix
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user