Authentication & Security
Learn how to implement JWT authentication in GEMVC. Master JWT setup, user login endpoints, and protecting routes with role-based access control.
What You'll Learn
JWT Setup
Configure JWT tokens in your application
User Login
Create login endpoint with JWT token generation
Protected Routes
Protect API endpoints with authentication and authorization
Video Coming Soon...
GEMVC Built-in JWT Authentication
GEMVC comes with a built-in JWT (JSON Web Token) authentication system. No need to install additional packages or configure complex middleware. The framework handles token creation, verification, and expiration automatically.
Key Features:
- ✓ HS256 Signature - Secure token signing with secret key
- ✓ Automatic Expiration - Tokens expire automatically (configurable)
- ✓ Role-Based Access Control - Multi-role support for authorization
- ✓ Token Renewal - Built-in token renewal mechanism
- ✓ Automatic Verification - Simple
auth()method call
Follow the guides below to set up JWT authentication, create login endpoints, and protect your API routes.
Authentication Flow
Here's how authentication works in GEMVC:
Built-in Security Features
GEMVC's JWT implementation includes automatic security features:
✓ Signature Verification
All tokens are signed with HS256 algorithm using TOKEN_SECRET. Forged tokens are automatically rejected.
✓ Expiration Validation
Tokens automatically expire based on configured time. Expired tokens are rejected with 401 Unauthorized.
✓ Role-Based Access Control
Multi-role support with simple auth(['admin']) method. Role escalation attacks are prevented.
✓ Token Renewal
Built-in token renewal mechanism allows extending token lifetime without re-authentication.
🔐 Ready to Secure Your API?
Start with JWT setup, then create a login endpoint, and finally protect your routes. Follow each guide to implement complete authentication in your GEMVC application!