import { Injectable , NestMiddleware , UnauthorizedException , Request , Response } from '@nestjs/common' ; import { RedisService } from '../Services/redis.service' ; @ Injectable ( ) export class BlacklistMiddleware implements NestMiddleware { constructor ( private readonly redisService ) { } async use ( @ Request ( ) req , @ Response ( ) _res , next ) { const token = req . headers . authorization . split ( ' ' ) [ 1 ] ; const isTokenDead = await this . redisService . getData ( token ) ; if ( isTokenDead !== null ) { throw new UnauthorizedException ( ) ; } next ( ) ; } }