UNPKG

@mridang/nestjs-auth

Version:

A comprehensive Auth.js integration for NestJS applications with TypeScript support, framework-agnostic HTTP adapters, and role-based access control

32 lines (31 loc) 1 kB
import { CanActivate, ExecutionContext } from '@nestjs/common'; import { Reflector } from '@nestjs/core'; /** * Guard that enforces role-based access control. Works in conjunction * with the @RequireRoles() decorator to restrict access to routes based on * user roles stored in the session. * * @example * ```ts * @Controller('admin') * @UseGuards(RolesGuard) * export class AdminController { * @Get('users') * @RequireRoles('admin', 'moderator') * getUsers() { * // Only users with 'admin' or 'moderator' roles can access * } * } * ``` */ export declare class RolesGuard implements CanActivate { private readonly reflector; constructor(reflector: Reflector); /** * Determines if the current request should be allowed based on user roles. * * @param context - The execution context containing request and handler info * @returns true if access should be granted, false otherwise */ canActivate(context: ExecutionContext): boolean; }