mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 02:16:16 +00:00
@ -1,4 +1,4 @@
|
||||
import { ExecutionContext, Injectable } from '@nestjs/common';
|
||||
import { ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { IS_PUBLIC_KEY } from '../decorators';
|
||||
@ -19,20 +19,16 @@ export class AccessTokenGuard extends AuthGuard('access-token') {
|
||||
return true;
|
||||
}
|
||||
|
||||
const isValid = await super.canActivate(context);
|
||||
|
||||
if (!isValid) {
|
||||
return false;
|
||||
}
|
||||
await super.canActivate(context);
|
||||
|
||||
const token = context.switchToHttp().getRequest().headers['authorization']?.split(' ')[1];
|
||||
|
||||
const isRevoked = await this.cacheService.get(token);
|
||||
|
||||
if (isRevoked) {
|
||||
return false;
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
|
||||
return !isRevoked;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user