temetro

Authentication

Sign up, sign in, manage sessions and clinics via the /api/auth endpoints.

Authentication is handled by Better Auth, mounted at /api/auth/*. These endpoints set and consume the session cookie used by the rest of the API.

Accounts

Sign up

curl -c cookies.txt -X POST http://localhost:4000/api/auth/sign-up/email \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Dr. Amina Yusuf",
    "email": "amina@example.com",
    "password": "a-long-secure-password"
  }'

A verification email is sent (printed to the backend logs if SMTP isn't configured). Verification is currently not required to sign in — see the roadmap.

Sign in

By email:

curl -c cookies.txt -X POST http://localhost:4000/api/auth/sign-in/email \
  -H "Content-Type: application/json" \
  -d '{ "email": "amina@example.com", "password": "a-long-secure-password" }'

Staff accounts created by an admin sign in by username instead:

curl -c cookies.txt -X POST http://localhost:4000/api/auth/sign-in/username \
  -H "Content-Type: application/json" \
  -d '{ "username": "frontdesk1", "password": "a-long-secure-password" }'

Both set the session cookie. Reuse it on subsequent requests with -b cookies.txt (cURL) or credentials: 'include' (fetch).

Clinics (organizations)

Clinics are Better Auth organizations. The endpoints you'll use most:

EndpointPurpose
POST /api/auth/organization/createCreate a clinic (you become its owner)
GET /api/auth/organization/listList clinics you belong to
POST /api/auth/organization/set-activeChoose the active clinic for your session
POST /api/auth/organization/invite-memberInvite someone by email with a role
POST /api/auth/organization/accept-invitationAccept an invitation

Set an active clinic first

Every /api/* data endpoint returns 403 until your session has an active organization. After sign-in, call organization/set-active with the clinic's id (the app does this for you automatically).

Other account endpoints

EndpointPurpose
GET /api/auth/get-sessionCurrent session and user
POST /api/auth/sign-outSign out (clears the cookie)
POST /api/auth/forget-passwordSend a password-reset email
POST /api/auth/reset-passwordComplete a reset with the emailed token

These are standard Better Auth routes — the Better Auth documentation covers their exact payloads. Sign-in is rate limited to 5 attempts per minute (sign-up 3, reset 3).

On this page