About Guards
Authentication and authorization guards using Elysia's beforeHandle hooks
Browse the snippets below to find the guards implementation you need for your Elysia project.
All Guards Snippets
JWT Auth Guard
JWT authentication guard with type-safe user context
- JWT verification
- Type-safe user context
- Token extraction
API Key Guard
API key authentication with constant-time comparison
- Constant-time comparison
- Multiple key support
- Environment-driven keys
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
How to Use
Install any snippet using the Hanma CLI:
npx hanma add --framework elysia
For example, to install the first snippet:
npx hanma add elysia-auth-guard --framework elysia