Documentation
API Reference
Authentication

Authentication API

Email/password authentication with optional TOTP 2FA.

Base URL

https://api.moontraze.com/api

Register

POST /api/auth
Content-Type: application/json
X-Project-Id: YOUR_PROJECT_ID
X-API-Key: YOUR_API_KEY
 
{
  "action": "register",
  "email": "user@example.com",
  "password": "secret123",
  "name": "John Doe"
}

Login

POST /api/auth
Content-Type: application/json
X-Project-Id: YOUR_PROJECT_ID
X-API-Key: YOUR_API_KEY
 
{
  "action": "login",
  "email": "user@example.com",
  "password": "secret123"
}

Verify TOTP

POST /api/auth
Content-Type: application/json
X-Project-Id: YOUR_PROJECT_ID
X-API-Key: YOUR_API_KEY
 
{
  "action": "login-verify",
  "loginTicket": "<from login>",
  "code": "123456"
}

Logout

POST /api/auth
Authorization: Bearer <token>
Content-Type: application/json
X-Project-Id: YOUR_PROJECT_ID
X-API-Key: YOUR_API_KEY
 
{
  "action": "logout"
}

Change Password (Logged In)

POST /api/auth
Authorization: Bearer <token>
Content-Type: application/json
X-Project-Id: YOUR_PROJECT_ID
X-API-Key: YOUR_API_KEY
 
{
  "action": "change-password",
  "currentPassword": "oldSecret",
  "newPassword": "newSecret"
}

Enroll MON Authenticator

POST /api/authenticator/enroll
Authorization: Bearer <token>
X-Project-Id: YOUR_PROJECT_ID
X-API-Key: YOUR_API_KEY

Confirm TOTP

POST /api/authenticator/confirm
Authorization: Bearer <token>
Content-Type: application/json
X-Project-Id: YOUR_PROJECT_ID
X-API-Key: YOUR_API_KEY
 
{
  "code": "123456"
}

Forgot Password

Step 1 — Verify TOTP

POST /api/authenticator/verify
Content-Type: application/json
X-Project-Id: YOUR_PROJECT_ID
X-API-Key: YOUR_API_KEY
 
{
  "email": "user@example.com",
  "code": "123456",
  "projectId": "YOUR_PROJECT_ID"
}

Step 2 — Reset

POST /api/auth
Content-Type: application/json
X-Project-Id: YOUR_PROJECT_ID
X-API-Key: YOUR_API_KEY
 
{
  "action": "reset-password",
  "email": "user@example.com",
  "verifyToken": "<from step 1>",
  "newPassword": "newSecret"
}

SDK Example

const result = await moon.auth.register('user@example.com', 'secret123', 'John');
moon.setToken(result.token);
 
const login = await moon.auth.login('user@example.com', 'secret123');
if (login.requiresTotp) {
  const verified = await moon.auth.verifyTotp(login.loginTicket, '123456');
  moon.setToken(verified.token);
}
 
// Logout
await moon.auth.logout();
 
// Change password
await moon.auth.changePassword('oldSecret', 'newSecret');