11import jwt from 'jsonwebtoken' ;
2- import { Request , Response } from 'express' ;
2+ import { Request , Response , NextFunction } from 'express' ;
3+ import { JwtPayload , VerifyErrors } from 'jsonwebtoken' ;
34import prisma from '../prisma/prisma' ;
45import { NotFoundException } from './errors.utils' ;
56import { User , User_Secure_Settings , User_Settings } from '@prisma/client' ;
@@ -24,7 +25,7 @@ export const prodHeaders = [
2425] ;
2526
2627// middleware function for production that will enforce jwt authorization
27- export const requireJwtProd = ( req : Request , res : Response , next : any ) => {
28+ export const requireJwtProd = ( req : Request , res : Response , next : NextFunction ) => {
2829 if (
2930 req . path === '/users/auth/login' || // logins dont have cookies yet
3031 req . path === '/' || // base route is available so aws can listen and check the health
@@ -36,9 +37,12 @@ export const requireJwtProd = (req: Request, res: Response, next: any) => {
3637
3738 if ( ! token ) return res . status ( 401 ) . json ( { message : 'Authentication Failed: Cookie not found!' } ) ;
3839
39- jwt . verify ( token , TOKEN_SECRET , ( err : any , decoded : any ) => {
40+ jwt . verify ( token , TOKEN_SECRET , ( err : VerifyErrors | null , decoded : string | JwtPayload | undefined ) => {
4041 if ( err ) return res . status ( 401 ) . json ( { message : 'Authentication Failed: Invalid JWT!' } ) ;
4142
43+ if ( ! decoded || typeof decoded === 'string' ) {
44+ return res . status ( 401 ) . json ( { message : 'Authentication Failed: Invalid JWT payload!' } ) ;
45+ }
4246 res . locals . userId = parseInt ( decoded . userId ) ;
4347
4448 next ( ) ;
@@ -47,7 +51,7 @@ export const requireJwtProd = (req: Request, res: Response, next: any) => {
4751} ;
4852
4953// middleware function for development that will enforce jwt authorization
50- export const requireJwtDev = ( req : Request , res : Response , next : any ) => {
54+ export const requireJwtDev = ( req : Request , res : Response , next : NextFunction ) => {
5155 if (
5256 req . path === '/users/auth/login/dev' || // logins dont have cookies yet
5357 req . path === '/' || // base route is available so aws can listen and check the health
0 commit comments