Authentication
Register User
Register a new user account
POST
Register User
Endpoint
Overview
Creates a new user account, generates a JWT token, creates an initial session, and logs audit events. The endpoint is protected by Arcjet with rate limiting (2 requests per token bucket).Request
User email address. Must be unique and valid email format.
User password. Minimum 8 characters. Will be hashed with bcrypt (10 rounds).
Optional display name for the user (1-100 characters).
Response
Created user object
JWT token for authentication. Valid for 7 days (configurable via
JWT_EXPIRES_IN).Implementation Details
Process Flow
- CORS Check: Validates CORS headers
- Arcjet Protection: Rate limiting (2 requests per bucket)
- Email Validation: Arcjet email validation
- Duplicate Check: Verifies email doesn’t exist
- Password Hashing: bcrypt with 10 rounds
- User Creation: Creates user in database
- IP Encryption: Encrypts IP address using user-specific key
- Session Creation: Creates session with JWT token
- Audit Logging: Logs
USER_REGISTERandSESSION_CREATEevents
Code Reference
Status Codes
User successfully created
Validation error (invalid email format, password too short, etc.)
User with this email already exists
Blocked by Arcjet (rate limit exceeded, bot detected, etc.)
Server error during user creation
Example Request
Example Response
Audit Events
This endpoint creates the following audit log entries:- USER_REGISTER: User account created
- SESSION_CREATE: Initial session created
Security Considerations
- Password is hashed with bcrypt (10 rounds) before storage
- IP address is encrypted using user-specific encryption key
- Email validation performed via Arcjet
- Rate limiting prevents abuse (2 requests per bucket)
- All actions are logged in audit trail
Register User