@UseGuards()

Attaches one or more guards that decide whether a request may proceed.

Since NestJS 10/11 Spec ↗

Syntax

@UseGuards(...guards: (CanActivate | Type<CanActivate>)[])

Parameters

NameTypeRequiredDescription
guards CanActivate[] No Guard instances or classes evaluated before the handler runs.

Returns

ClassDecorator | MethodDecorator — A decorator applied at controller or handler level.

Examples

import { Controller, Get, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';

@Controller('profile')
export class ProfileController {
  @Get()
  @UseGuards(AuthGuard('jwt'))
  me() {
    return { ok: true };
  }
}

Notes

Guards run after middleware but before pipes and interceptors. A guard returning false (or throwing) blocks the request with a 403. Combine with @SetMetadata() and Reflector for role-based access control.