npx vratix init
β
Automatic Reuse Detection
β
Username and Password Authentication
β
JWT Access Tokens
β
Refresh Tokens
β
Reply Attack Protection
ποΈ
HTTP Cookie Sessions
About
The Auth Basic Module provides essential authentication functionality for backend services. It supports quick setup for user signup and login with username and password, along with session management. As a core module, it enables secure access to routes and serves as the foundation for many other API modules.
Installation
To add the Auth Basic Module to your project, run:
.env
Add the following environment variables to your .env
file:
- JWT_SECRET_KEY: Secret key used for signing and verifying JWTs
- Default: None (required)
- Example:
JWT_SECRET_KEY=your-secret-key
- JWT_ISSUER: Issuer identifier for JWTs to ensure theyβre issued by your backend
- Default: None (required)
- Example:
JWT_ISSUER=com.yourdomain
Usage
Import the router from @/routes/auth.js
in your main entry point file (e.g., server.ts
):
Middleware
This module provides a protectedRoute
middleware to secure endpoints, requiring a valid JWT access token for access.
Endpoints
The Auth Basic Module exposes the following endpoints:
Method | Endpoint | Description |
---|---|---|
POST | /signup | Creates a new user account and returns session tokens |
POST | /login | Authenticates the user and returns session tokens |
POST | /refresh-token | Issues a new JWT access token and rotates the refresh token |
Errors
Below are common errors with solutions for this module:
Error Code | Name | Solution |
---|---|---|
409 | UsernameNotAvailable | Ensure username is unique |
409 | InvalidLoginCredentials | Verify the credentials are correct |
403 | ForbiddenError | User attempted to access a protected route with an invalid token |
500 | JWTEnvVariableMissing | Verify .env file configuration |
Examples
To explore sample requests and responses, download our Postman collection: