Nestjs auth bootstrap
Skill AccentioStudios/nestjs-auth-bootstrap/.claude/skills/nestjs-auth-bootstrap
Use this skill when the user asks to scaffold authentication, JWT auth, or role/permission-based authorization in a NestJS project. Triggers: "set up auth", "add JWT auth", "scaffold authentication", "necesito auth en mi proyecto NestJS", "crea sistema de roles y permisos", "bootstrap nestjs auth". The skill analyzes the target project, asks clarifying questions, installs dependencies, and scaffolds AuthModule + Passport JWT strategy + global CompositeAuthGuard + decorators (@Public, @RequirePermission, @CurrentUser) + OAuth2-style Permission enum (READ/WRITE/MANAGE per resource) + ROLE_PERMISSIONS matrix + refresh tokens + ThrottlerGuard. Generates target-project docs (CLAUDE.md section + docs/auth/EXTENDING.md) so future agents can extend the system without losing context.From its SKILL.md
npx -y skills add AccentioStudios/nestjs-auth-bootstrap --skill nestjs-auth-bootstrapAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
8.8 KB, as published. Nobody here has run it
nestjs-auth-bootstrap
Scaffold a complete NestJS authentication and authorization system into a target
project, replicating a battle-tested architecture: Passport+JWT strategies, a
single global CompositeAuthGuard, decorator-driven permission checks, and an
OAuth2-style Permission enum (READ/WRITE/MANAGE per resource).
When to use
Trigger this skill when the user asks any of:
- "Add JWT auth to this NestJS project"
- "Scaffold an auth module with roles and permissions"
- "Necesito sistema de auth con roles en este NestJS"
- "Bootstrap auth in my Nest app"
- "Set up login + refresh + permission guards"
When NOT to use
- Project is not NestJS (check
package.jsonfor@nestjs/core). - User wants an external OAuth2 provider integration (Auth0, Cognito, Clerk) — this skill scaffolds first-party JWT auth, not federated identity.
- User only wants a single guard/decorator added to an existing auth system —
point them at
docs/auth/EXTENDING.mdif it exists in the project, or toreferences/permission-model.mdhere.
Non-negotiable design decisions
These are baked into the templates. If the user wants to deviate, complete the skill first and then refactor — do not improvise mid-scaffold.
- One global guard:
CompositeAuthGuardregistered viaAPP_GUARD. It handles@Publicskip, JWT validation, and permission checks in one pass. No per-handler@UseGuards()stacking. - Decorator-driven:
@Public,@RequirePermission(...),@CurrentUser()are the only auth surface in handlers.@Roles(...)exists for legacy needs but@RequirePermissionis preferred. - OAuth2 scope-style permissions:
<RESOURCE>_READ,<RESOURCE>_WRITE,<RESOURCE>_MANAGE. WRITE = create+update+delete on the resource. MANAGE = admin operations (assigning roles, deleting any record, etc). - Base roles:
SUPER_ADMIN(everything),ADMIN(READ+WRITE on user/org, no MANAGE on user roles),USER(READ on own resource). Extra roles via user input. - Always included: refresh tokens,
ThrottlerGuard, globalValidationPipewith{ whitelist: true, transform: true, forbidNonWhitelisted: true }. - NOT included by default: account lockout, second auth strategy
(team/api-key), audit logging. These have extension recipes in
docs/auth/EXTENDING.mdof the target project. - Single login endpoint:
POST /auth/loginserves all roles. Admin vs non-admin distinction is by permission checks on protected endpoints, not separate login flows.
Workflow — 5 phases (BLOCKING)
Each phase blocks until the previous one is acknowledged. Do not write project files before Phase 4.
Phase 1 — Analyze
Use Read, Glob, Grep to inspect the target project. Collect:
- NestJS presence + version:
package.json→@nestjs/coreversion. - Package manager: presence of
package-lock.json(npm),pnpm-lock.yaml(pnpm), oryarn.lock(yarn). Use whatever is present. - ORM: presence of
mongoose,@nestjs/typeorm+typeorm, orprisma+@prisma/clientindependencies. - Existing auth artifacts: search for
AuthModule,JwtStrategy,JwtAuthGuard,permission-policy,@Public(),@RequirePermission. List what exists and where. - Folder conventions: read
src/tree. Note if it usessrc/modules/,src/common/,src/core/(preferred), or different layout. app.module.ts: read it; identify where to mergeAuthModuleimport andAPP_GUARDproviders.main.ts: check whetherValidationPipeis already global..env.example: check for existingJWT_*keys.
Report findings as a markdown table. Do not edit anything yet.
Phase 2 — Ask
Use AskUserQuestion for adaptive clarification. Ask only what could not be
inferred in Phase 1. Always ask:
- If existing auth detected: "Auth artifacts found at X. Abort, merge (extend existing), or overwrite?"
- If no ORM detected: "No ORM found. Pick one: mongoose / TypeORM / Prisma (skill installs it), or generate stub repository (you wire it later)."
- Extra resources for Permission enum: "Beyond
USERandORGANIZATION, list resources to add (e.g.,PROJECT,INVOICE). Each gets READ/WRITE/MANAGE." - Extra roles beyond SUPER_ADMIN/ADMIN/USER: "Need additional roles? (e.g., MODERATOR, AUDITOR)"
- If folder layout differs: "Project uses
<detected-layout>. Confirm target paths for: auth module, common (guards/decorators), core (enums, authorization)." - Multi-tenancy: "Should JWT carry
orgclaim and DTOs includeorganizationId? (yes for multi-tenant SaaS, no for single-tenant)."
Phase 3 — Confirm
Print a single confirmation block listing:
- Files to create (full paths)
- Files to modify (
app.module.ts,main.ts,.env.example, possiblyCLAUDE.md) - Dependencies to install (with the detected package manager command)
- Final shape of Permission enum and ROLE_PERMISSIONS matrix
- Final shape of UserRole enum
Wait for explicit OK. If the user requests changes, loop back to Phase 2.
Phase 4 — Execute
Run in this order:
- Install dependencies with the detected package manager:
- Always:
@nestjs/jwt @nestjs/passport @nestjs/throttler @nestjs/config passport passport-jwt bcrypt class-validator class-transformer joi - Always (dev):
@types/passport-jwt @types/bcrypt - If installing mongoose:
@nestjs/mongoose mongoose - If installing typeorm:
@nestjs/typeorm typeorm+ driver (ask which DB) - If installing prisma:
prisma @prisma/client(also runnpx prisma initif no schema.prisma)
- Always:
- Render templates from
templates/with substitution. Seereferences/adaptation-matrix.mdfor the variable map. Conditional sections use{{#if ORM_MONGOOSE}} ... {{/if}}style — render manually with simple string replacement, no template engine needed. - Write files to the target paths.
- Merge
app.module.ts: followtemplates/app-module.snippet.md. - Merge
main.ts: ensureValidationPipeblock exists. - Append/create
.env.example: add JWT keys. - Append
CLAUDE.md: add the "Authentication & Authorization" section fromtemplates/docs/CLAUDE-auth-section.md.tpl(create the file if it doesn't exist). - Create
docs/auth/EXTENDING.md: render fromtemplates/docs/EXTENDING.md.tplwith the chosen role/resource names.
Phase 5 — Verify
- Run
npx tsc --noEmit(ornpm run build). Report errors verbatim. Fix trivial path issues (e.g.,.jsextension on imports for ESM projects vs no extension for CJS — detect fromtsconfig.jsonmodulefield). - List the new endpoints:
POST /auth/login,POST /auth/refresh,GET /auth/me. - Suggest verification cURL commands (referencing
references/verification-checklist.md). - Tell the user where
EXTENDING.mdlives and what it covers.
Outputs
After a successful run the target project gains:
src/modules/auth/— full modulesrc/common/guards/— 4 guardssrc/common/decorators/— 4 decoratorssrc/core/enums.ts(or appended) withUserRolesrc/core/authorization/permission-policy.tswithPermission,ROLE_PERMISSIONS,ASSIGNABLE_ROLES, helperssrc/config/auth.config.ts- Persistence layer (variant by ORM):
Userschema/entity/model - Updated
app.module.ts,main.ts,.env.example - New/updated
CLAUDE.mdwith auth section - New
docs/auth/EXTENDING.mdrunbook
How to iterate this skill
This skill lives at .claude/skills/nestjs-auth-bootstrap/ in the arka-api
repo. When you find a case the templates don't handle (new ORM, edge layout,
missing variable), update the relevant template or reference doc and bump
metadata.version in this file's frontmatter. Commit with a descriptive
message; the skill is meant to be a living artifact.