50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import {
|
|
CanActivate,
|
|
ExecutionContext,
|
|
Injectable,
|
|
ForbiddenException,
|
|
} from '@nestjs/common';
|
|
import { RedisHandlers } from '@/src/utils/auth/redis_handlers';
|
|
|
|
@Injectable()
|
|
export class AuthControlGuard implements CanActivate {
|
|
constructor(private cacheService: RedisHandlers) {}
|
|
|
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
const req = context.switchToHttp().getRequest();
|
|
const accessToken = this.cacheService.mergeLoginKey(req);
|
|
console.log('AuthControlGuard', accessToken);
|
|
// const hasAccess = accessObject.permissions?.some(
|
|
// (p: any) => p.method === method && p.url === path,
|
|
// );
|
|
|
|
// if (!hasAccess) {
|
|
// throw new ForbiddenException('Access denied to this route');
|
|
// }
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
@Injectable()
|
|
export class EndpointControlGuard implements CanActivate {
|
|
constructor(private cacheService: RedisHandlers) {}
|
|
|
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
const req = context.switchToHttp().getRequest();
|
|
const selectToken = this.cacheService.mergeSelectKey(req);
|
|
const method = req.method;
|
|
const path = req.route?.path;
|
|
console.log('EndpointControlGuard', selectToken, method, path);
|
|
// const hasAccess = accessObject.permissions?.some(
|
|
// (p: any) => p.method === method && p.url === path,
|
|
// );
|
|
|
|
// if (!hasAccess) {
|
|
// throw new ForbiddenException('Access denied to this route');
|
|
// }
|
|
|
|
return true;
|
|
}
|
|
}
|