/nestjs:nestjs-authfrom NestJS
Adds sign-in, sessions, bearer tokens, API keys, and permissions to NestJS apps using @nestjs/authentication and @nestjs/authorization. Covers timing-safe password checks, global guards with @Public(), policies with @Can(), and JWT secret/token format fixes.
Ships in NestJS. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Use the first-party packages rather than assembling auth from @nestjs/jwt, Passport and bcrypt:
npm i @nestjs/authentication @nestjs/authorization
@nestjs/authentication (docs: https://docs.nestjs.com/security/authentication.md): a global guard that puts every route behind sign-in, @Public() to open one, @Authenticate({ optional: true }), @CurrentUser(), PasswordHasher (scrypt), sessions, TokenService (JWT access + rotating refresh tokens), ApiKeyProvider, TOTP, magic links, OIDC. No third-party dependencies.@nestjs/authorization (docs: https://docs.nestjs.com/security/authorization.md): policies as providers, @Can(Policy, 'ability') on routes, AuthorizationService.authorize() in services. Denies a route that declares no check.PasswordHasher.verify(password, found?.passwordHash), and only then decide. With no user it checks a dummy hash, so an unknown email takes as long as a wrong password. Never if (!user) throw before the hash check: the faster answer tells anyone which emails are registered. Hash with passwordHasher.hash(); inject PasswordHasher (the module provides it).@Post() + @HttpCode(200): it creates nothing, so not 201.accessToken.key must be at least 32 bytes for HS256 (openssl rand -base64 32); a shorter one stops the app at startup. Never hash, pad or derive a longer key from a short secret: tokens are then signed with a different key, and anything that verifies them with the configured secret rejects them.JWT_SECRET, a default value, tokens other services verify), keep it exactly. If it's under 32 bytes, sign and verify with @nestjs/jwt using that secret, and plug verification into @nestjs/authentication as your own AuthenticationProvider, so the global guard, @Public() and @CurrentUser() still work. Say in your summary that the secret is too short for production. Code: references/authentication.md.TokenService.refresh() spends each refresh token; a reused one is a 401 and revokes its whole family, so the client must sign in again. Access tokens stay valid until they expire: keep ttl short.AuthenticationContext (requireUser()), a singleton backed by AsyncLocalStorage: no request-scoped providers, and run({ user }, fn) for workers and tests.validate()/authenticate(), and read roles from it, not from token claims: a role change or a deleted user then takes effect at once.AuthenticationModule before AuthorizationModule (the app refuses to start otherwise). A custom guard that sets request.user goes in as APP_GUARD before AuthorizationModule.@nestjs/authorization denies every route that declares nothing: once AuthorizationModule is imported, a signed-in user gets 403 on any handler without @Can(), @Can.Anyone() or @Public() (the startup log lists them). Adding it to an existing app, put @Can.Anyone() on routes any signed-in user may call (e.g. GET /me, the user's own resources) and re-test them.@Can() or ForbiddenException).takeUntil() on a revocation signal, shown in nestjs-feature's references/http.md.HttpException ({ statusCode, message, errorCode } plus a WWW-Authenticate header): a global exception filter can reshape it like any other error..overrideProvider(PasswordHasher).useValue(new PasswordHasher({ logN: 10 })). Throttle sign-in (nestjs-production).NODE_ENV=production the module refuses to start that way. A bearer-only API can turn refresh tokens off: refreshToken: false.| The app needs | Use |
|---|---|
| Bearer JWTs it issues itself, secret up to you | accessToken options + JwtBearerProvider + TokenService.issue() |
| A secret or token format fixed by the task | @nestjs/jwt + your own AuthenticationProvider |
| Browser sessions | SessionCookieProvider + SignInService.signIn() |
| Keys for scripts and partners | ApiKeyProvider (keys prefix_<id>_<secret>, stored as SHA-256) or your own provider for another header; manage keys only from a session (@Authenticate({ providers: [SessionAuth] })), so a leaked key can't mint more |
| Roles or ownership checks | @nestjs/authorization policies |
Code for each row, checked against @nestjs/authentication 0.1.6 and @nestjs/authorization 0.1.4: references/authentication.md, references/authorization.md.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
6 skills in this plugin
/nestjsNestJS, the TypeScript framework for Node.js backends. How to start a project non-interactively with the Nest CLI, the project layout and module system, where the current docs are, and the mistakes agents make in Nest apps that still pass their tests. Use when creating or extending a NestJS application./nestjs-dataDatabases in a NestJS application with the first-party @nestjs/drizzle and @nestjs/typeorm integrations - registering the database, injecting it into services, schemas or entities, migrations, transactions, and writes that stay correct under concurrent requests. Use when adding or changing persistence in a NestJS application./nestjs-featureAdd or change HTTP endpoints in a NestJS application - modules, controllers and services, request validation (Zod or another Standard Schema library with @Body({ schema }), or class-validator DTOs), status codes, error response bodies, request IDs, versioning and Server-Sent Events. Use when adding or changing endpoints in a NestJS application./nestjs-productionProduction setup for a NestJS application with first-party packages - configuration and env validation (@nestjs/config), structured logs, observability with NestJS Observe (@nestjs/observe), health and readiness checks (@nestjs/terminus), rate limiting (@nestjs/throttler), OpenAPI (@nestjs/swagger), graceful shutdown and deployment behind a load balancer. Use when preparing a NestJS application for production, or adding any of these to one./nestjs-testingUnit, service and end-to-end tests for a NestJS application with @nestjs/testing - Test.createTestingModule, mocking and overriding providers and global guards, Supertest against the real app, signing test users in, SSE, test databases, Vitest in ESM projects (Jest in CommonJS ones). Use when writing, running or fixing tests in a NestJS application.npx claudepluginhub nestjs/agent-skills --plugin nestjs2 plugins ship this exact skill · first indexed Nov 20, 2026
Other plugins' skills for the same job