Skip to content

Auth API

Authentication, token management, and password reset endpoints.

These endpoints handle user registration (via invite), login, token verification, and password recovery.

Endpoints

MethodPathDescriptionAuth Required
POST/api/auth/create-userCreate a user from an invitationNo
POST/api/auth/loginLogin with email and passwordNo
POST/api/auth/forgot-passwordSend a password-reset emailNo
POST/api/auth/reset-passwordReset password with a reset tokenNo
GET/api/auth/verify-tokenVerify the main auth tokenYes
GET/api/auth/verify-token-forgotVerify a forgot-password tokenNo
GET/api/auth/verify-token-registerVerify a registration tokenNo
GET/api/auth/verify-token-inviteVerify an invitation tokenNo
POST/api/auth/refresh-tokenRefresh an expired access tokenNo (cookie)
POST/api/auth/heartbeatReport user activityYes

POST /api/auth/create-user

Create a new user account from a valid invitation.

Request Body

json
{
  "email": "john@example.com",
  "password": "SecureP@ss123",
  "name": "John Doe",
  "invitationId": "inv_abc123def456"
}
FieldTypeRequiredDescription
emailstringYesEmail address (must match invite)
passwordstringYesPassword (min 8 characters)
namestringYesFull name of the user
invitationIdstringYesInvitation ID received via email

Response — 201 Created

json
{
  "success": true,
  "message": "User created successfully",
  "data": {
    "userId": "usr_789xyz",
    "email": "john@example.com",
    "name": "John Doe"
  }
}

Error — 400 Bad Request

json
{
  "success": false,
  "message": "Invalid or expired invitation"
}

POST /api/auth/login

Authenticate with email and password. Returns access and refresh tokens.

Request Body

json
{
  "email": "john@example.com",
  "password": "SecureP@ss123"
}
FieldTypeRequiredDescription
emailstringYesRegistered email address
passwordstringYesAccount password

Response — 200 OK

json
{
  "success": true,
  "data": {
    "token": "v4.public.eyJ...",
    "refreshToken": "v4.public.eyJ...",
    "user": {
      "id": "usr_789xyz",
      "email": "john@example.com",
      "name": "John Doe",
      "role": "manager",
      "orgId": "org_abc123"
    }
  }
}

TIP

The refreshToken is also set as an HTTP-only cookie for the /refresh-token endpoint.

Error — 401 Unauthorized

json
{
  "success": false,
  "message": "Invalid email or password"
}

POST /api/auth/forgot-password

Send a password-reset link to the given email address.

Request Body

json
{
  "email": "john@example.com"
}
FieldTypeRequiredDescription
emailstringYesRegistered email address

Response — 200 OK

json
{
  "success": true,
  "message": "Password reset email sent"
}

Error — 404 Not Found

json
{
  "success": false,
  "message": "No account found with this email"
}

POST /api/auth/reset-password

Reset a user's password using the token from the reset email.

Request Body

json
{
  "token": "reset_token_value",
  "newPassword": "NewSecureP@ss456"
}
FieldTypeRequiredDescription
tokenstringYesReset token from the email link
newPasswordstringYesNew password (min 8 characters)

Response — 200 OK

json
{
  "success": true,
  "message": "Password reset successfully"
}

Error — 400 Bad Request

json
{
  "success": false,
  "message": "Invalid or expired reset token"
}

GET /api/auth/verify-token

Verify that the caller's access token is valid.

Authentication

http
Authorization: Bearer <token>

Response — 200 OK

json
{
  "success": true,
  "data": {
    "valid": true,
    "userId": "usr_789xyz",
    "email": "john@example.com",
    "role": "manager"
  }
}

Error — 401 Unauthorized

json
{
  "success": false,
  "message": "Token is invalid or expired"
}

GET /api/auth/verify-token-forgot

Verify a forgot-password token is still valid before showing the reset form.

Query Parameters

ParameterTypeRequiredDescription
tokenstringYesThe forgot-password token

Response — 200 OK

json
{
  "success": true,
  "data": {
    "valid": true,
    "email": "john@example.com"
  }
}

Error — 400 Bad Request

json
{
  "success": false,
  "message": "Invalid or expired token"
}

GET /api/auth/verify-token-register

Verify a registration token before showing the registration form.

Query Parameters

ParameterTypeRequiredDescription
tokenstringYesThe registration token

Response — 200 OK

json
{
  "success": true,
  "data": {
    "valid": true,
    "email": "john@example.com"
  }
}

Error — 400 Bad Request

json
{
  "success": false,
  "message": "Invalid or expired registration token"
}

GET /api/auth/verify-token-invite

Verify an invitation token before displaying the accept-invite form.

Query Parameters

ParameterTypeRequiredDescription
tokenstringYesThe invitation token

Response — 200 OK

json
{
  "success": true,
  "data": {
    "valid": true,
    "email": "john@example.com",
    "orgName": "Grand Hotel",
    "role": "receptionist"
  }
}

Error — 400 Bad Request

json
{
  "success": false,
  "message": "Invalid or expired invitation token"
}

POST /api/auth/refresh-token

Refresh an expired access token using the refresh token stored in an HTTP-only cookie.

Authentication

No Authorization header required. The refresh token is read from the refreshToken cookie set during login.

Response — 200 OK

json
{
  "success": true,
  "data": {
    "token": "v4.public.eyJ..."
  }
}

Error — 401 Unauthorized

json
{
  "success": false,
  "message": "Refresh token is invalid or expired"
}

POST /api/auth/heartbeat

Report user activity to keep the session alive and track online status.

Authentication

http
Authorization: Bearer <token>

Request Body

json
{
  "userid": "usr_789xyz"
}
FieldTypeRequiredDescription
useridstringYesThe authenticated user's ID

Response — 200 OK

json
{
  "success": true,
  "message": "Heartbeat received"
}

Error — 401 Unauthorized

json
{
  "success": false,
  "message": "Token is invalid or expired"
}

Released under the MIT License.