HTTP API (sessions)
AuthWAPI’s account routes are Better Auth’s, served under BASE_URL/api/auth. They
use a session cookie, so they suit a web app served from AuthWAPI’s own origin, scripts and tests. For an app
on another origin, or an API that needs tokens, use OAuth / OIDC instead.
Every route with its request and response schema is in the API reference, and as a file in
/openapi.json.
Rules for every request
Section titled “Rules for every request”- Host must be
BASE_URL’s host or a name inALLOWED_HOSTS, else421 unknown_host. - Origin, if sent, must be
BASE_URL’s origin (or anALLOWED_HOSTSname with the same scheme), else403 untrusted_origin. - A
POSTto these routes that sends any cookie must sendOrigin(-H 'origin: http://localhost:4000'in curl), else403 MISSING_OR_NULL_ORIGINand nothing happens. Browsers send it on their own. Calls without a cookie don’t need it. - Bodies are JSON (
content-type: application/json). - Rate limits apply per IP; see Configuration.
- Errors from account routes look like
{"message":"Email not verified","code":"EMAIL_NOT_VERIFIED"}. OAuth routes answer{"error":"invalid_grant","error_description":"…"}.
Sessions
Section titled “Sessions”Sign-in sets the better-auth.session_token cookie (HttpOnly, SameSite=Lax, 7 days; named
__Secure-better-auth.session_token when BASE_URL is https). Send it back on every call.
| Route | What it does |
|---|---|
POST /sign-up/email {name, email, password} |
Creates the account and emails a verification link. The answer looks the same whether or not the address already has an account. |
POST /sign-in/email {email, password} |
Sets the session cookie. 403 EMAIL_NOT_VERIFIED until the email is verified. |
GET /get-session |
The session and user, or null. |
POST /sign-out |
Ends the session and revokes the user’s OAuth refresh tokens. |
GET /list-sessions |
The user’s sessions. |
POST /revoke-session {token}, /revoke-sessions, /revoke-other-sessions |
End sessions. Each also revokes the user’s OAuth refresh tokens. |
POST /change-password {currentPassword, newPassword, revokeOtherSessions?} |
Changes the password. |
POST /send-verification-email {email} |
Sends the verification email again. |
curl -c jar -X POST http://localhost:4000/api/auth/sign-in/email \ -H 'content-type: application/json' \ -d '{"email":"ada@example.com","password":"correct-horse-battery"}'curl -b jar http://localhost:4000/api/auth/get-sessioncurl -b jar -H 'origin: http://localhost:4000' -X POST http://localhost:4000/api/auth/sign-out # {"success":true}Magic links
Section titled “Magic links”curl -X POST http://localhost:4000/api/auth/sign-in/magic-link \ -H 'content-type: application/json' \ -d '{"email":"ada@example.com","callbackURL":"/"}'# {"status":true}- Signs in an existing account only; it never creates one.
- The link works once, for 5 minutes, and is stored hashed.
- For an address with no account the answer is the same, but nothing is sent. One address gets at most one link a minute.
- A magic link also verifies the email. Any password set before the email was verified is removed (use password reset to set one).
callbackURL(andnewUserCallbackURL,errorCallbackURL) must be onBASE_URLor anALLOWED_HOSTSname.
The emailed link (/api/auth/magic-link/verify?token=…) is a page: opening it asks “Sign in as
ada@example.com?” and only the Continue button signs in.
Password reset
Section titled “Password reset”curl -X POST http://localhost:4000/api/auth/request-password-reset \ -H 'content-type: application/json' \ -d '{"email":"ada@example.com","redirectTo":"/reset-password"}'# {"status":true,"message":"If this email exists in our system, check your email for the reset link"}The email’s link is BASE_URL/api/auth/reset-password/<token>?callbackURL=…. Opening it redirects to the hosted
reset page. To finish over the API, take the token from the link’s path:
curl -X POST http://localhost:4000/api/auth/reset-password \ -H 'content-type: application/json' \ -d '{"token":"<token>","newPassword":"new-password-456"}'# {"status":true}A reset ends every session and revokes every OAuth refresh token the user has.
Other Better Auth routes
Section titled “Other Better Auth routes”Better Auth mounts more routes under /api/auth (updating the user, changing the email, social sign-in, client
administration). AuthWAPI M1 doesn’t configure, test or support them, so they’re left out of these docs and the
API reference.