Overview
This page contains 6 code snippets for implementing Authorization in Elysia. Each snippet is production-ready and can be copy-pasted directly into your project.
Available Snippets
JWT Plugin
JWT authentication with role-based access control
- JWT sign/verify
- Role-based access
- Token validation
Bearer Token Plugin
Bearer token extraction from multiple sources
- Multi-source extraction
- Custom extractors
- Require guard
Security Headers
Security headers middleware with CSP, HSTS, and more
- Content-Security-Policy
- Strict-Transport-Security
- X-Frame-Options
JWT Auth Guard
JWT authentication guard with type-safe user context
- JWT verification
- Type-safe user context
- Token extraction
Role Guard
Role-based access control with role hierarchy
- Role hierarchy
- Multiple role check
- Minimum role level
Ownership Guard
Resource ownership validation for user-specific access
- Generic resource support
- Bypass roles for admins
- Flexible owner field
Frequently Asked Questions
How do I implement Authorization in Elysia?
Browse the snippets above and copy the code that matches your needs. Each snippet includes installation instructions and usage examples.
Are these snippets production-ready?
Yes, all snippets are designed for production use. However, always review and test them in your specific context before deployment.
Can I use these snippets with other Elysia versions?
These snippets are designed for the current major version of the framework. Check the snippet documentation for version compatibility notes.