mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
2c3fb15263
Prettier on every new or moved file that was not formatted, so lint:format holds them; the files taken off the format baseline are the ones that moved or were formatted on the way.
20 lines
653 B
TypeScript
20 lines
653 B
TypeScript
import { CanActivate, ExecutionContext, HttpException, Injectable } from '@nestjs/common';
|
|
|
|
import type { Request } from 'express';
|
|
|
|
/**
|
|
* Mirrors the legacy `adminOnly` middleware: requires an authenticated admin.
|
|
* Use together with JwtAuthGuard (which populates req.user):
|
|
* `@UseGuards(JwtAuthGuard, AdminGuard)`.
|
|
*/
|
|
@Injectable()
|
|
export class AdminGuard implements CanActivate {
|
|
canActivate(context: ExecutionContext): boolean {
|
|
const req = context.switchToHttp().getRequest<Request>();
|
|
if (!req.user || req.user.role !== 'admin') {
|
|
throw new HttpException({ error: 'Admin access required' }, 403);
|
|
}
|
|
return true;
|
|
}
|
|
}
|