nestjs-authentication

Implement JWT authentication and RBAC authorization in NestJS TypeScript backends.

2|Updated Dec 5, 2025
One-click install
npx skills add https://github.com/AgentiveCity/SkillFactory --skill nestjs-authentication
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nestjs-authentication
Source: https://github.com/AgentiveCity/SkillFactory/tree/main/.claude/skills/nestjs-authentication
Command: npx skills add https://github.com/AgentiveCity/SkillFactory --skill nestjs-authentication

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Designing, implementing, or refactoring authentication and authorization in NestJS TypeScript backends, including JWT, sessions, refresh tokens, guards, and roles, can be complex and security-critical. This Skill automates the setup of robust auth modules and secure API endpoints, reducing development time and ensuring best practices.

Core Features & Use Cases

  • Comprehensive Auth Module Setup: Create or refactor auth modules with login, signup, and logout endpoints, integrating with UsersService and password hashing.
  • JWT & Token Management: Implement JWT access tokens (and optional refresh tokens) using @nestjs/jwt and passport-jwt for stateless API authentication.
  • Role-Based Access Control (RBAC): Implement guards and decorators for role-based and permissions-based access control, securing routes at class or method level.

Quick Start

Implement JWT login and protect /admin routes in this NestJS app, adding signup, login, and me endpoints, and refactor our existing auth module to use guards and decorators cleanly.

Frequently Asked Questions about nestjs-authentication

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement JWT authentication in a NestJS backend?

JWT authentication in NestJS uses @nestjs/jwt and passport-jwt to create stateless API token verification. Implement a login endpoint that issues access tokens, apply JWT guards to protected routes, and configure the JwtStrategy to validate incoming tokens automatically.

What's the best way to add role-based access control to NestJS endpoints?

Role-based access control uses guards and decorators to enforce permissions at the route or controller level. Define roles in your user entity, create custom guards that check user roles, and apply decorators to restrict endpoints so only authorized users can access them.

How do I set up signup, login, and logout in NestJS?

Build an auth module with endpoints for signup (validate and hash passwords, store users), login (verify credentials, issue JWT tokens), and logout (if using refresh tokens, invalidate them). Integrate with UsersService and apply password hashing for security.

Can I use refresh tokens with JWT in NestJS?

Yes, refresh tokens extend session lifetime without re-authentication. Issue a short-lived access token and longer-lived refresh token on login, store refresh tokens securely, and create an endpoint that exchanges a valid refresh token for a new access token.

Do I need external identity providers for NestJS authentication?

External providers are optional; NestJS supports both built-in local authentication (username/password) and integration with OAuth2 or SAML providers via Passport strategies. Choose based on your security requirements and user management needs.

What are the security considerations for storing and handling JWT tokens?

Store tokens in secure, httpOnly cookies when possible to prevent XSS attacks. Use strong secrets for signing, set short expiration times for access tokens, validate token signatures server-side, and never expose secrets in client-side code or version control.