agentsclimarketplace

Nestjs guards auth

Skill dkmqflx/nestjs-best-practices-plugin/plugins/nestjs-best-practices/skills/nestjs-guards-auth

Claude Code plugin: 12 NestJS best-practice skills (90 rules) grounded in the official NestJS docs

Install
npx -y skills add dkmqflx/nestjs-best-practices-plugin --skill nestjs-guards-auth

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 1 stars1 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.

What its author says it does

Copied from the file, not written here

NestJS guards, authentication, and authorization best practices. Use when implementing or reviewing auth in NestJS — guards, JWT/Passport strategies, RBAC, route protection. Triggers on CanActivate, AuthGuard, JwtStrategy, @Roles, @Public, or Reflector.

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

3.1 KB, as published. Nobody here has run it

NestJS Guards, Auth & Authorization

Best practices for securing NestJS applications with guards, Passport-based JWT authentication, and role-based authorization. Verified against the current NestJS v10/v11 documentation (guards, authentication, authorization, and the Passport recipe).

The core mental model: authentication (authn) answers "who are you?" and runs as a guard that validates a credential and attaches a typed user to the request. Authorization (authz) answers "are you allowed?" and runs as a separate guard that reads route metadata via Reflector and compares it against that user. Keep these two concerns in distinct guards, declare a strong JWT config from the environment, and never leak whether a credential was valid.

When to Apply

Reference these rules when:

  • Implementing login / token issuance or protecting routes in NestJS
  • Writing or reviewing a CanActivate guard, AuthGuard, or JwtStrategy
  • Setting up Passport (@nestjs/passport + passport-jwt)
  • Adding role-based access control (@Roles, RolesGuard)
  • Registering a global auth guard with per-route opt-out (@Public)
  • Reviewing how req.user is typed, how secrets are configured, or how auth failures are surfaced to clients

Rules

RuleImpactSummary
separate-authn-from-authzHIGHKeep identity verification and permission checks in distinct guards
passport-jwt-strategyHIGHUse @nestjs/passport + a passport-jwt strategy class for JWT auth
global-auth-guard-with-publicHIGHRegister a global auth guard and opt out via @Public() metadata
roles-guard-rbacHIGHDrive RBAC with @Roles() metadata read by a RolesGuard via Reflector
hash-passwordsCRITICALNever store plaintext; hash with bcrypt/argon2 + salt
type-the-request-userMEDIUMStrongly type req.user; never trust an unvalidated payload
dont-leak-auth-detailsHIGHReturn generic 401/403; don't reveal whether a user exists
validate-jwt-configCRITICALLoad a strong secret from config/env with sane expiry; verify signature and expiration

How to Use

Read individual rule files for the rationale and incorrect/correct code:

rules/passport-jwt-strategy.md
rules/roles-guard-rbac.md

Each rule file contains a short explanation of why it matters, followed by an Incorrect and a Correct TypeScript example. Apply CRITICAL and HIGH impact rules first when reviewing existing auth code.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.