Auth

Sign-up, passwords, emailed links and codes, Google and GitHub, sessions, row-level security and the admin API.

/auth/v1 signs in your app's people: email and password, emailed sign-in links and six-digit codes, Google and GitHub. It speaks the API supabase-js uses, so supabase.auth.signUp, signInWithPassword, signInWithOtp, signInWithOAuth, getUser and signOut work against Forkbase.

Keys and tokens

Every request carries an API key in the apikey header:

  • anon from browsers and phone apps,
  • service_role from your servers only.

A signed-in person's app also sends Authorization: Bearer <access token>. Access tokens are JWTs signed with EdDSA. Check them offline against GET /auth/v1/.well-known/jwks.json. They live auth.access_ttl_s (an hour).

Refresh tokens rotate on every use. A spent refresh token presented again ends its whole session: someone copied it.

The claims your SQL sees: sub (the user's id), role (authenticated), email, aal, session_id, app_metadata, user_metadata. In SQL, auth.uid() (text), auth.role() and auth.jwt() read them.

Routes

RouteBody
GET /settingswhich sign-ins are on: passwords, magic_links, signups, providers
POST /signup{email, password, name?, data?, redirect_to?}makes the user, signs them in, emails a verification link
POST /token?grant_type=password{email, password}sign in
POST /token?grant_type=refresh_token{refresh_token}a new access token
POST /otp{email, code_challenge, redirect_to?}emails a sign-in link and a six-digit code
POST /token?grant_type=email_code{email, code}sign in with the code
POST /token?grant_type=pkce{auth_code, code_verifier}redeem the ?code= a link or social sign-in returned
GET /authorize?provider=google|github&code_challenge=&redirect_to=start social sign-in
POST /recover{email, redirect_to?}emails a reset link (?type=recovery&token=)
POST /reset{token, password}set the new password
POST /resend{email}another verification email
GET /userthe signed-in person
PUT /user{password?, name?, data?}change own password, name, data
POST /logout?scope=local|global|othersthis session, all sessions, or the others

Sign-in answers {access_token, token_type, expires_in, expires_at, refresh_token, user}.

Emailed links and social sign-ins send the person back to your page (auth.site_url, or an allowed redirect_to) with a one-time ?code=. Only the PKCE code_verifier your page kept can redeem it (grant_type=pkce). supabase-js does this for you with flowType: 'pkce'.

redirect_to must be auth.site_url or start with one of auth.redirect_urls.

Limits

  • Failed sign-ins: 10 per 15 minutes per address, and per IP when a proxy sets X-Forwarded-For.
  • Emails: 5 of a kind per address per hour.

Admin (service key)

Route
GET /admin/users, POST /admin/userslist (?page=&per_page=&q=, newest first), make a user (email, password, name, email_confirm, app_metadata, user_metadata)
GET, PUT, DELETE /admin/users/{id}one user: read, change (email, password, name, email_confirm, disabled, metadata), delete
GET /admin/users/{id}/sessions, POST /admin/users/{id}/logouttheir sessions; sign them out everywhere
POST /admin/invite{email, redirect_to?}: emails an invitation
GET /admin/eventsthe sign-in audit log
GET /admin/keys, POST /admin/keys/rotate, POST /admin/keys/{kid}/retirethe signing keys: list, add a new one, retire an old one

Rotate signing keys without signing anyone out: rotate adds a key that signs from now on while the old one still verifies; retire the old one once its tokens have expired.

Settings

All in [auth] in forkbase.toml (see Configuration):

TOML
[auth]
external_url = "https://api.myapp.com"   # where this server is reached; tokens name it, links point at it
site_url = "https://myapp.com"           # your app: where people come back to
redirect_urls = ["https://myapp.com/auth", "http://localhost:3000/auth"]   # http:// or https:// only
origins = ["https://admin.myapp.com"]    # extra browser origins (site_url's is always allowed)
signups = true
passwords = true
magic_links = true
require_verified = false                 # true: a password sign-in waits for a verified address
access_ttl_s = 3600

Email

auth.email.mode:

Mode
log (default)emails, links included, are written to the server's log. Development only.
smtpsent through smtp_host, smtp_port (587), smtp_user, smtp_password, smtp_tls (starttls, tls or none)
fileappended as JSON lines to auth.email.file (tests, or piping to another sender)
offanything that needs an email is refused

Set from to "My App <noreply@myapp.com>". Put the password in FORKBASE_SMTP_PASSWORD, not the file.

Google and GitHub

TOML
[auth.google]
client_id = "....apps.googleusercontent.com"   # secret: FORKBASE_GOOGLE_CLIENT_SECRET
[auth.github]
client_id = "Iv1...."                          # secret: FORKBASE_GITHUB_CLIENT_SECRET

Register the callback https://<external_url>/auth/v1/callback/google (or /github) with the provider. A provider is on when it has both a client id and a secret.

Row-level security

Requests to /rest/v1, /storage/v1 and /realtime/v1 run as a database role:

CallerRole
the anon key aloneanon
a signed-in personauthenticated
the service keyservice_role (bypasses RLS)

Forkbase makes these roles when it starts. Write policies as in Supabase:

SQL
create table notes (id text primary key, owner text not null default auth.uid(), body text);
grant select, insert, update, delete on notes to authenticated;
alter table notes enable row level security;
create policy own on notes for all to authenticated
  using (owner = auth.uid()) with check (owner = auth.uid());

People live in auth.users. Don't write that table by hand; use the routes above.

Something wrong or missing? Edit this page on GitHub or open an issue.

Auth · Forkbase