---
name: "nestjs-guards-jwt-passport"
description: "Secure API endpoints with Passport JWT strategies, refresh tokens, and Role-Based Guards."
metadata:
  author: "NestJS"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "create nestjs authguard"
  - "passport-jwt strategy nestjs"
  - "roles guard nestjs"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# NestJS Authentication Guards & Passport JWT Strategies

Implements NestJS security: AuthGuard('jwt'), extracting tokens from Bearer headers or cookies, authoring RolesGuard with Reflector metadata, implementing refreshToken rotation, and generating access tokens.

## When to Invoke
Invoke this skill whenever you need to:
- create nestjs authguard
- passport-jwt strategy nestjs
- roles guard nestjs

## Execution SOP & Rules
1. Define JwtStrategy extending PassportStrategy(Strategy) validating JWT payload against database.
2. Create custom decorator @Roles(...roles: Role[]) using SetMetadata().
3. Implement CanActivate in RolesGuard using reflector.get<Role[]>(ROLES_KEY, context.getHandler()).
4. Apply globally or at controller level: @UseGuards(JwtAuthGuard, RolesGuard).

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
