Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Shashank-H/gaiter-gaurd/llms.txt
Use this file to discover all available pages before exploring further.
Overview
JWT (JSON Web Token) authentication is used for dashboard users to manage agents, services, and approval workflows. GaiterGuard uses a dual-token system:- Access Token: Short-lived (15 minutes) for API requests
- Refresh Token: Long-lived (7 days) for obtaining new access tokens
Token Configuration
From/home/daytona/workspace/source/backend/src/config/env.ts:26-27:
JWT_ACCESS_EXPIRY:15m(15 minutes)JWT_REFRESH_EXPIRY:7d(7 days)
Authentication Endpoints
Register User
Create a new dashboard user account.Request Body
Valid email address. Must match format:
/^[^\s@]+@[^\s@]+\.[^\s@]+$/Password with minimum 8 characters. Hashed using Argon2id (memory cost: 65536, time cost: 2).
Response Fields
Error Responses
Email Already Exists (409 Conflict)
Validation Error (400 Bad Request)
Login
Authenticate with email and password to receive access and refresh tokens.Request Body
User’s registered email address
User’s password
Response Fields
JWT access token valid for 15 minutes. Use in
Authorization: Bearer {token} header.JWT refresh token valid for 7 days. Use to obtain new access tokens. Stored as hashed value in database.
Authenticated user information
Error Responses
Invalid Credentials (401 Unauthorized)
- Email doesn’t exist in database
- Password verification fails
Refresh Access Token
Exchange a valid refresh token for a new access + refresh token pair. Implements token rotation - the old refresh token is invalidated.Request Body
Valid refresh token from login or previous refresh
Response Fields
New JWT access token valid for 15 minutes
New JWT refresh token valid for 7 days. The old refresh token is deleted from database.
Token Rotation Flow
From/home/daytona/workspace/source/backend/src/services/auth.service.ts:135-196:
- Verify refresh token JWT signature
- Extract user ID from token
- Query
refresh_tokenstable for matching hash - Delete old refresh token (rotation)
- Generate new access + refresh token pair
- Store new refresh token hash in database
- Return new tokens
Error Responses
Invalid Refresh Token (401 Unauthorized)
- Token signature verification fails
- Token is expired
- Token hash not found in database
- Token already used (due to rotation)
Get Current User
Retrieve authenticated user information.Headers
Bearer token format:
Bearer YOUR_ACCESS_TOKENResponse Fields
Using JWT Tokens
Making Authenticated Requests
Include the access token in theAuthorization header:
Access Token Expiry Handling
Implement automatic token refresh when access token expires:JWT Token Structure
Access Token
Generated by/home/daytona/workspace/source/backend/src/utils/jwt.ts:36-44:
Decoded Payload
- Algorithm:
HS256(HMAC-SHA256) - No
typeclaim (distinguishes from refresh tokens)
Refresh Token
Generated by/home/daytona/workspace/source/backend/src/utils/jwt.ts:51-62:
Decoded Payload
- Algorithm:
HS256 - Includes
type: "refresh"claim for validation
Authentication Middleware
TherequireAuth middleware (from backend/src/middleware/auth.ts:29) protects dashboard routes:
- Extract
Authorizationheader - Validate
Bearerprefix format - Extract token after prefix
- Verify token signature and expiry using
joselibrary - Extract user ID from
subclaim - Return
{ userId }for route handlers
Protected Routes
All agent management endpoints require JWT authentication:POST /agents- Create agentGET /agents- List agentsGET /agents/:id- Get agent detailsPUT /agents/:id- Update agentDELETE /agents/:id- Delete agentPUT /agents/:id/services- Update agent services
Error Responses
Missing Authorization Header
Invalid Header Format
Bearer (note the space).
Invalid or Expired Token
- Token signature verification fails
- Token is expired
- Token is malformed
Security Features
Password Hashing
Password Hashing
Passwords are hashed using Argon2id with strong parameters:
- Memory cost: 65536 KB
- Time cost: 2 iterations
- Built-in salt generation
backend/src/services/auth.service.ts:54-58Token Rotation
Token Rotation
Refresh tokens are single-use. Each refresh operation:
- Deletes the old refresh token from database
- Issues a new refresh token
- Prevents token replay attacks
backend/src/services/auth.service.ts:176Token Storage
Token Storage
- Refresh tokens stored as hashed values in database
- Access tokens are stateless (not stored)
- Tokens use
HS256algorithm with secret key
Short-Lived Access Tokens
Short-Lived Access Tokens
15-minute access token expiry minimizes exposure window if token is compromised. Use refresh tokens to obtain new access tokens.
Best Practices
Store Tokens Securely
- Use secure HTTP-only cookies for web apps
- Store in encrypted storage on mobile
- Never expose tokens in URLs or logs
Handle Token Expiry Gracefully
- Implement automatic refresh on 401 errors
- Pre-emptively refresh before expiry
- Clear tokens on logout
Use HTTPS
Always transmit tokens over HTTPS to prevent interception
Implementation Reference
Source code locations:- Auth routes:
backend/src/routes/auth.ts - Auth service:
backend/src/services/auth.service.ts - JWT utilities:
backend/src/utils/jwt.ts - Auth middleware:
backend/src/middleware/auth.ts:29 - Config:
backend/src/config/env.ts