feat: admin endpoints

This commit is contained in:
2024-06-11 12:33:50 +02:00
parent 958f9bae30
commit 9875b665b7
9 changed files with 327 additions and 22 deletions

View File

@@ -0,0 +1,22 @@
import { ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common'
import { JwtAuthGuard } from './jwt-auth.guard'
@Injectable()
export class AdminGuard extends JwtAuthGuard {
async canActivate(context: ExecutionContext): Promise<boolean> {
const canActivate = await super.canActivate(context)
if (!canActivate) {
return false
}
const request = context.switchToHttp().getRequest()
const user = request.user
if (!user.isAdmin) {
throw new UnauthorizedException('You do not have permission to access this resource')
}
return true
}
}