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