NestJS Auth Guard
Rule: Before writing any guard, confirm which permission strategy the project uses. Never mix strategies in the same project.
Before Starting
- Check what already exists in
src/auth/andsrc/security/:bash ~/.claude/skills/project-scan/scripts/scan.sh - Load
references/strategies.md— the two available strategies
Steps
Adding to an existing auth setup
- Follow the exact same guard and decorator pattern already in the project
- Never create a second auth module — extend the existing one
Setting up auth from scratch
- Ask first: "Does this project need simple role-based guards or dynamic permission-based (CASL)?"
- Implement the chosen strategy fully before writing any feature code
- Place everything in
src/auth/— JWT guard, strategy, decorators, and types - Configure
JwtModule.registerAsyncwith env-based secret inauth.module.ts - Register
JwtAuthGuardas a global guard inAppModule— opt-out with@Public()decorator