Stratal API Reference
    Preparing search index...

    Function UseGuards

    • UseGuards Decorator

      Applies one or more guards to a controller or method. Guards are executed in order and all must pass for the request to proceed.

      Execution Order:

      1. Request → Global Middlewares → Route Middlewares
      2. Guards (controller-level, then method-level)
      3. Route Handler

      Guard Resolution:

      • Guard classes are resolved from the request-scoped DI container
      • Guard instances (from factory functions) are used directly

      Parameters

      • ...guards: Guard[]

        Guard classes or instances to apply

      Returns ClassDecorator & MethodDecorator

      @Controller('/api/v1/profile')
      @UseGuards(AuthGuard())
      export class ProfileController {
      show() { } // Requires authentication
      }
      @Controller('/api/v1/students')
      @UseGuards(AuthGuard({ scopes: ['students:read'] }))
      export class StudentsController {
      index() { } // Requires 'students:read' permission
      }
      @Controller('/api/v1/students')
      @UseGuards(AuthGuard()) // Controller-level: auth only
      export class StudentsController {
      index() { } // Auth only (inherited)

      @UseGuards(AuthGuard({ scopes: ['students:create'] }))
      create() { } // Auth + 'students:create' permission
      }
      @UseGuards(AuthGuard(), RateLimitGuard(), CustomGuard())
      export class SecureController {
      // All guards must pass
      }