About Decorators
Custom decorators for controllers and methods
Browse the snippets below to find the decorators implementation you need for your NestJS project.
All Decorators Snippets
Current User
Extract authenticated user from request
- Extract full user object
- Extract specific property
- Type-safe user data
Roles Decorator
Role-based access control decorator
- Role enum included
- Single role requirement
- Multiple roles (OR logic)
Public Route
Mark routes as public to skip auth
- Skip auth guards
- Works with global guards
- Simple metadata decorator
Auth Decorator
Combined authentication decorator
- JWT + Roles combined
- Swagger integration
- AdminOnly shortcut
API Response
Swagger response decorators
- Paginated response decorator
- Success response wrapper
- Common error responses
Message Patterns
Enhanced microservice message decorators
- Message with metadata
- Event patterns
- Versioned messages
How to Use
Install any snippet using the Hanma CLI:
npx hanma add --framework nest
For example, to install the first snippet:
npx hanma add current-user --framework nest