Skip to main content
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

string
required
User email address. Must be unique and valid email format.
string
required
User password. Minimum 8 characters. Will be hashed with bcrypt (10 rounds).
string
Optional display name for the user (1-100 characters).

Response

object
Created user object
string
JWT token for authentication. Valid for 7 days (configurable via JWT_EXPIRES_IN).

Implementation Details

Process Flow

  1. CORS Check: Validates CORS headers
  2. Arcjet Protection: Rate limiting (2 requests per bucket)
  3. Email Validation: Arcjet email validation
  4. Duplicate Check: Verifies email doesn’t exist
  5. Password Hashing: bcrypt with 10 rounds
  6. User Creation: Creates user in database
  7. IP Encryption: Encrypts IP address using user-specific key
  8. Session Creation: Creates session with JWT token
  9. Audit Logging: Logs USER_REGISTER and SESSION_CREATE events

Code Reference

Status Codes

Created
User successfully created
Bad Request
Validation error (invalid email format, password too short, etc.)
Conflict
User with this email already exists
Forbidden
Blocked by Arcjet (rate limit exceeded, bot detected, etc.)
Internal Server Error
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

Body

application/json
email
string<email>
required
password
string
required
Minimum string length: 8
username
string

Response

User created successfully

user
object
token
string