nestjs-guards-interceptors

Enforce authentication, authorization, logging, and transformation in NestJS applications.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill nestjs-guards-interceptors
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nestjs-guards-interceptors
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-nestjs/skills/nestjs-guards-interceptors
Command: npx skills add https://github.com/TheBushidoCollective/han --skill nestjs-guards-interceptors

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill teaches implementing cross-cutting concerns in NestJS using guards and interceptors to enforce authentication, authorization, auditing, and data transformation.

Core Features & Use Cases

  • Auth guards: JWT, session, and API key authentication patterns.
  • Context-aware guards: Access request context for fine-grained decisions.
  • Interceptors: Transform, log, and handle errors at a centralized layer.
  • RBAC: Role-based authorization patterns.

Quick Start

Implement a BasicGuard with CanActivate and apply it to a controller route.

Frequently Asked Questions about nestjs-guards-interceptors

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

FAQPage Schema
How do I implement authentication guards in NestJS?

Authentication guards in NestJS enforce login requirements by implementing CanActivate and validating tokens or sessions before route access. Guards inspect ExecutionContext, verify JWT, session, or API key credentials, and either allow or reject requests based on validation results.

What's the difference between guards and interceptors in NestJS?

Guards determine whether a request proceeds to a handler using CanActivate logic; interceptors transform, log, or handle errors before and after execution. Guards enforce access control; interceptors shape data and manage cross-cutting concerns like logging and response formatting.

How do I implement role-based access control in NestJS?

Role-based authorization in NestJS uses guards to extract user roles from ExecutionContext, compare them against required permissions, and deny access if the user lacks necessary roles. Combine metadata decorators with CanActivate guards to enforce RBAC per route.

Can I use multiple authentication strategies with NestJS guards?

Yes, NestJS supports multi-strategy authentication by composing multiple guards or implementing a single guard that tries JWT, session, and API key validation sequentially. Guards access ExecutionContext to extract credentials from headers, cookies, or query parameters for each strategy.

How do I log requests and responses in NestJS?

Interceptors log HTTP requests and responses by implementing NestInterceptor, accessing ExecutionContext, and using RxJS operators to capture and record data before and after handler execution. Centralize logging logic in a reusable interceptor applied globally or per route.

What authentication patterns does NestJS guard implementation support?

NestJS guards support JWT token validation, session-based authentication, and API key verification. Each pattern uses ExecutionContext to extract credentials from Authorization headers, cookies, or custom headers, then validate against stored secrets or databases.