Skip to main content

Two Backends

Primary Backend (Port 3001)
  • Admin operations
  • Cookie-based JWT auth
  • Full CRUD for users, buildings, sectors
Mobile Backend (Port 3002)
  • Mobile operations
  • Phone + OTP auth
  • User profiles, simple queries

Authentication Examples

Primary Backend (Admin)

const response = await fetch('http://localhost:3001/api/v1/auth/signin', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  credentials: 'include',
  body: JSON.stringify({ email, password })
});

Mobile Backend (Phone + OTP)

// Step 1: Sign in
const authResponse = await fetch('http://localhost:3002/api/v1/auth/signin', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ phoneNumber })
});
const { accessToken } = await authResponse.json();

// Step 2: Request OTP
await fetch('http://localhost:3002/api/v1/auth/otp/create', {
  method: 'POST',
  headers: { 'Authorization': `Bearer ${accessToken}` }
});

// Step 3: Validate OTP
const sessionResponse = await fetch('http://localhost:3002/api/v1/auth/otp/validate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${accessToken}`
  },
  body: JSON.stringify({ otp })
});
const { sessionToken } = await sessionResponse.json();

Response Format

All responses follow this structure:
{
  "success": true,
  "data": { ... }
}
Errors:
{
  "success": false,
  "error": {
    "message": "Error description",
    "code": "ERROR_CODE"
  }
}

Next Steps