feat: implement AdminGuard and QueryGuard for enhanced access control; refactor API and query handling; add deleteQuery method in QueryHandlerService; update QueryResponse type for improved response handling
This commit is contained in:
27
src/api/guards/admin.guard.ts
Normal file
27
src/api/guards/admin.guard.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import {
|
||||
CanActivate,
|
||||
ExecutionContext,
|
||||
Inject,
|
||||
Injectable,
|
||||
UnauthorizedException,
|
||||
} from "@nestjs/common";
|
||||
import { ApiService } from "../api.service";
|
||||
|
||||
@Injectable()
|
||||
export class AdminGuard implements CanActivate {
|
||||
constructor(
|
||||
@Inject(ApiService)
|
||||
private readonly apiService: ApiService
|
||||
) {}
|
||||
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const apiToken = request.apiToken;
|
||||
|
||||
if (!apiToken || !apiToken.isAdmin) {
|
||||
throw new UnauthorizedException("Admin privileges are required");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user