Authentication
Overview of Postbase authentication — dashboard auth, API keys, JWT, and the full SDK Auth API.
Authentication
Postbase ships with two authentication systems: dashboard auth for the Postbase admin UI, and the SDK Auth API for your end-user applications.
API Keys
Every project has two API keys generated with nanoid:
pb_anon_<64chars>— Anon key. Used by end-user clients. Subject to RLS policies.pb_service_<64chars>— Service role key. Bypasses RLS. Only for trusted server-side code.
All SDK API routes require the anon key (or service key for admin endpoints) in the Authorization: Bearer <key> header.
JWT Tokens
Postbase uses a lightweight HS256 JWT implementation via the Web Crypto API — no external library required. It works in Node 18+ and Edge runtime.
Token TTLs: access token = 1 hour, refresh token = 7 days (rotated on every use).
JWT payload shape:
{ "sub": "<userId>", "pid": "<projectId>", "email": "user@example.com", "role": "authenticated", "iat": 1700000000, "exp": 1700003600 }Magic Link Flow
Client calls
POST /api/auth/v1/otpwith the user email.Postbase sends a magic link email via nodemailer.
User clicks the link →
GET /api/auth/v1/verifyissues a session, sets thepostbase-sessioncookie, and redirects.