import { ExpressMiddlewareInterface , Middleware , Req , Res , } from 'routing-controllers' ; import express from 'express' ; import { Authentication } from '../utils/Authenticate' ; @ Middleware ( { type : 'before' } ) export class CheckJwt implements ExpressMiddlewareInterface { constructor ( ) { } use ( @ Req ( ) request , @ Res ( ) response , next ) { const jwt = request . headers . authorization as string ; if ( jwt !== undefined ) { const bearerToken = jwt . replace ( /Bearer\s/ , '' ) ; const token = Authentication . refreshToken ( bearerToken ) ; response . setHeader ( 'authorization' , `Bearer ${ token }` ) ; } next ( ) ; } }