Skip to content

Auth

Auth is built into the Supatype server. It signs users in, issues the tokens every request carries, and those tokens are what your schema’s access rules check.

How it runs

The auth service is part of supatype-server, the same process that serves REST, GraphQL, storage and functions. It answers under /auth/v1 on your project’s API URL. It keeps its users, identities and sessions in the auth schema of your project’s database and runs its own migrations when the server starts.

  • supatype dev with database.provider: "docker" (what supatype init writes): the server runs in the Compose stack behind Kong. Your API URL is API_EXTERNAL_URL in the project’s .env.
  • supatype dev with database.provider: "native": the server runs as a local process on server.port, 18471 by default.
  • Self-host: supatype self-host compose up runs the same server image. It needs JWT_SECRET in .env and fills in a blank ANON_KEY or SERVICE_ROLE_KEY from it. See Self-hosting.

In local dev, sign-ups are confirmed automatically, so a new user gets a session straight away with no email round trip. A self-hosted stack sends a confirmation link instead. See Email sign-in and confirmation.

Sign-in methods

Each method below is a call on supatype.auth. The client page shows the common ones in use.

MethodClient callDefault
Email and passwordsignUp, signInWithPasswordOn
Magic link or email codesignInWithOtp({ email }), then verifyOtp for a codeOn, needs a mail provider to deliver
Phone code (SMS, or WhatsApp with Twilio)signInWithOtp({ phone }), verifyOtpOff, needs an SMS provider
OAuthsignInWithOAuth({ provider })Off until a provider is configured
Provider ID token (native Apple or Google sign-in)signInWithIdTokenOff until the provider is configured
AnonymoussignInAnonymouslyOff
SAML single sign-on, by email domainsignInWithSSO({ domain }) or signInWithSSO({ providerId })Off until auth.sso.saml.enabled. See Single sign-on

Password reset is resetPasswordForEmail, and updateUser changes the email, password or user metadata of the signed-in user. Passwords must be at least 6 characters unless you raise SUPATYPE_PASSWORD_MIN_LENGTH.

signUp takes options.data for user metadata, which comes back on user.userMetadata.

signInWithOtp creates the user when they do not exist, unless you pass options.createUser: false. For a phone, pass phone and optionally options.channel ("sms" or "whatsapp"), then call verifyOtp with type: "sms". resend({ type, email }) or resend({ type, phone }) sends a confirmation or code again, where type is "signup", "sms", "email_change" or "phone_change".

For a password reset, wait for initialize() on the page the link opens, then call updateUser({ password }). A recovery link, or verifyOtp with type: "recovery", emits PASSWORD_RECOVERY once the session exists.

Auth errors

Auth calls put the auth server’s code in error.code, beside message and status. Branch on the code, not the message: invalid_credentials, email_not_confirmed, weak_password, user_already_exists, email_exists, and otp_expired for an expired link. error.code is absent only when the answer carried none, such as a gateway’s HTML error page.

Multi-factor

supatype.auth.mfa has enroll, challenge, verify, challengeAndVerify and unenroll. TOTP authenticator apps are on by default. Phone factors are off by default and need an SMS provider.

enroll({ factorType: "totp" }) returns the factor’s id and a QR code (totp.qrCode) and URI (totp.uri) to show the user. challengeAndVerify({ factorId, code }) is challenge then verify in one call. Call the two separately when the code arrives later, as an SMS does. A verify raises the session to AAL2 and emits MFA_CHALLENGE_VERIFIED. listFactors() returns every factor in all and the verified ones in totp and phone. getAuthenticatorAssuranceLevel() reports the current and next level.

Anonymous users

An anonymous sign-in creates a real user with a user id and a session. Turn it on with SUPATYPE_EXTERNAL_ANONYMOUS_USERS_ENABLED=true. Because the user has an id, an anonymous user passes LoggedIn and can own rows. The token carries is_anonymous: true.

signInAnonymously({ options: { data, captchaToken } }) takes optional metadata and a captcha token, and the user comes back with isAnonymous: true. The flag survives a reload: a restored session keeps it, and a session saved without it takes it from the token’s is_anonymous claim.

Keep anonymous users out

To let only registered users do something, test the claim as well as the sign-in:

import type { All, Claim, Eq, Literal, LoggedIn } from "@supatype/types"
type Registered = All<[LoggedIn, Eq<Claim<"is_anonymous">, Literal<"false">>]>

Use it like any rule, for example access: { read: LoggedIn, create: Registered }, so a guest can read but only a registered user can create. The auth server puts is_anonymous in every access token it issues, true for a guest and false for a real account, so the rule admits exactly the users who signed up or added an email or phone. A token without the claim, such as one minted by your own code, is denied.

Write the literal as the string "false": a claim is read as text, and that form works on every engine version. Literal<false> means the same thing on engines after 0.9.0, which read the claim as a JSON boolean when it is compared with a boolean. Engine 0.9.0 and earlier refuse it at push with operator does not exist: text = boolean.

Anonymous users do not last forever. When the auth server’s database cleanup is on (SUPATYPE_DB_CLEANUP_ENABLED=true, off by default), it deletes every anonymous user 30 days after the account was created, even one still in use. Rows whose user field declares onDelete: "cascade" are deleted with it, a "setNull" field is cleared, and a field without onDelete keeps an id that no longer matches a user. Prompt guests to add an email or phone before then: once they do, is_anonymous is false and the cleanup leaves them alone.

OAuth providers

Each provider is switched on with environment variables named after it. For GitHub:

.env
SUPATYPE_EXTERNAL_GITHUB_ENABLED=true
SUPATYPE_EXTERNAL_GITHUB_CLIENT_ID=your-client-id
SUPATYPE_EXTERNAL_GITHUB_SECRET=your-client-secret
SUPATYPE_EXTERNAL_GITHUB_REDIRECT_URI=<your API URL>/auth/v1/callback

The redirect URI is the auth service’s callback: /auth/v1/callback on your API URL. Your API URL is API_EXTERNAL_URL in .env: under Docker, the project’s gateway (http://localhost: and its SUPATYPE_KONG_PORT); with the native provider, the server itself (http://localhost:18471 unless you set server.port). Register the same URL with the provider. A provider with no client id, secret or redirect URI is refused when someone tries to use it.

Supported provider names: apple, azure, bitbucket, discord, facebook, figma, fly, github, gitlab, google, kakao, keycloak, linkedin_oidc, notion, slack_oidc, snapchat, spotify, twitch, twitter, x, workos and zoom. The auth server also accepts vercel_marketplace, and the older linkedin and slack, which the _oidc versions replace. Upper-case the name for the variable, so linkedin_oidc becomes SUPATYPE_EXTERNAL_LINKEDIN_OIDC_ENABLED.

The sign-in round trip

const { data, error } = await supatype.auth.signInWithOAuth({
provider: "github",
options: { redirectTo: "http://localhost:5173/auth/callback" },
})
if (error) throw new Error(error.message)
window.location.assign(data.url)
// On /auth/callback
// The client finishes the sign-in in the URL when it starts; initialize() waits for that.
const { error: callbackError } = await supatype.auth.initialize()
if (callbackError) console.error(callbackError.message)

signInWithOAuth returns the URL; it does not navigate for you. redirectTo must be on the same host as SITE_URL, a loopback address, or match an entry in SUPATYPE_URI_ALLOW_LIST (comma-separated, globs allowed). Anything else sends the user to SITE_URL instead. An app on another domain, or a mobile deep link, needs an allow list entry.

The web default is the implicit flow, which returns tokens in the URL fragment. Pass flowType: "pkce" in the options for a code exchange instead; mobile apps should always use PKCE. The client finishes either from the URL when it starts, and removes the tokens from the address bar; initialize() resolves once it has, with any error the provider sent back. Do not call getSessionFromUrl as well: the URL no longer carries the tokens by then, so it answers with an error.

exchangeCodeForSession(code) does the PKCE exchange on its own. options.scopes asks the provider for extra scopes.

Sessions and tokens

A session is a short-lived access token and a refresh token.

  • The access token is a JWT signed with JWT_SECRET, valid for one hour. The client sends it as Authorization: Bearer on every request.
  • The client refreshes it about a minute before it expires, and again on load if a saved session has already expired. If the refresh fails, the session is cleared rather than kept with a dead token.
  • Refresh tokens rotate: each refresh issues a new one.
  • signOut takes no arguments. It ends every session the user has on the server, not just this device’s, and clears it locally.

In the browser the session is saved to localStorage under supatype.auth.session and mirrored to a cookie named st-auth-token, which @supatype/ssr reads on the server. Set auth: { persistSession: false }, storageKey or cookiePrefix on createClient to change this. On React Native, createNativeClient from @supatype/react-native stores the session in expo-secure-store or AsyncStorage.

Auth events

onAuthStateChange calls back at once with SIGNED_IN or SIGNED_OUT, then on each of these:

EventWhen
SIGNED_INA session starts while signed out
SIGNED_OUTThe session is cleared
TOKEN_REFRESHEDThe session is replaced while signed in
USER_UPDATEDupdateUser succeeded. The session passed to the callback carries the updated user
PASSWORD_RECOVERYA password reset link or code produced a session, after its SIGNED_IN
MFA_CHALLENGE_VERIFIEDAn MFA verify raised the session to AAL2

What the token says

ClaimMeaning
subThe user id
roleThe database role the API runs the request as: authenticated for a signed-in user
email, phoneThe user’s contact details
app_metadataSet only through the admin API. Holds the application role that Role<> checks
user_metadataSet by the user, for example through signUp options or updateUser. Never trust it for access
aal, amrAssurance level and how the user signed in, for MFA
session_id, is_anonymousThe session, and whether the user signed in anonymously

Requests made with only the anon key have no user. Requests made with the service role key pass every access rule; keep that key on the server.

Access rules

The access rules you declare in the schema compile to Postgres row level security that reads the verified token. Every request runs with the token’s claims available to the database, so the same rule holds for REST, GraphQL and realtime. The rules themselves are listed on the schema page.

schema/index.ts
import type { Model, UUID, SupatypeAuthUserId, Public, LoggedIn, Owner } from "@supatype/types"
export type Profile = Model<{
id: SupatypeAuthUserId
display_name: string
}, {
access: { read: Public; create: Owner<"id">; update: Owner<"id">; delete: Owner<"id"> }
}>
export type Bookmark = Model<{
id: UUID
owner_id: SupatypeAuthUserId
post_id: UUID
}, {
access: { read: Owner<"owner_id">; create: LoggedIn; update: Owner<"owner_id">; delete: Owner<"owner_id"> }
}>

A profile keyed on the user id lets each user write only their own row. Bookmarks are private to whoever saved them.

What the rules become

The engine installs a small set of SQL functions in the auth schema, and every policy calls them:

Rule or functionSQL
auth.uid()The token’s sub as a uuid, or NULL when there is no user
auth.role()app_metadata.role, falling back to the top-level role claim, then anon
auth.claim(path)A nested claim by dotted path, used by Claim<>
LoggedIn(SELECT auth.uid()) IS NOT NULL
Owner<"owner_id">(SELECT auth.uid()) = "owner_id"
Role<"admin">(SELECT auth.role()) = 'admin'

Because auth.uid() is NULL for a request with no user, an owner rule never matches an anonymous request, even on a row whose owner column is empty. The calls are wrapped in SELECT so Postgres evaluates them once per query rather than once per row.

To give a user an application role for Role<>, set app_metadata.role through the auth admin API with the service role key. Users cannot set it themselves.

Pre-built UI

Two packages give you ready-made sign-in screens. Both use useAuth() from @supatype/react, so they must sit inside a <SupatypeProvider>.

PackageComponents
@supatype/react-authLoginForm, SignUpForm, ForgotPasswordForm, UpdatePasswordForm, MagicLinkForm, OAuthButton, SSOForm (see Single sign-on)
@supatype/react-native-authLoginForm, SignUpForm, MagicLinkForm, OAuthButton, ResetPassword, AuthGate, AuthThemeProvider

Web

src/SignIn.tsx
import { SupatypeProvider } from "@supatype/react"
import { LoginForm, OAuthButton } from "@supatype/react-auth"
import { supatype } from "./supatype"
export function SignIn() {
return (
<SupatypeProvider client={supatype}>
<LoginForm onSuccess={() => window.location.assign("/")} />
<OAuthButton provider="github" redirectTo="http://localhost:5173/auth/callback" />
</SupatypeProvider>
)
}

The web forms are plain, unstyled markup: pass className and labels to fit your app. OAuthButton has a default style and an icon for GitHub, Google and Apple, which a className replaces. It sends the browser to the provider; the client finishes the sign-in on your callback page by itself, and initialize() tells you how it went.

When an agent connects to your app MCP, a person approves it on a page of yours. McpConsent is that screen for React (@supatype/react), Vue, Svelte and Solid. All four say the same thing: who is asking, the address the browser returns to with its host in bold, an Unverified badge for an app that registered itself (an app that is identified by an address it publishes is shown by that address’s host instead, with no badge), the access in words (Read your data, Read and change your data), then Approve and Deny. They sign the person in first through the sign-in you give them, and send the browser where the auth server says once it is answered.

The Vue, Svelte and Solid screens are unstyled: semantic markup under stable class names (supatype-mcp-consent, with __title, __client, __badge, __identified, __identified-host, __scopes, __host, __address, __actions, __approve, __deny, __error) and no inline styles, so they work under a strict Content Security Policy. Style them with your own CSS. Each takes request (auth.oauth from the client, the authorizationId the auth server put in the page’s address, and the serverName to show), auth (state is "loading", "signed-out" or "signed-in", and an optional onSignOut) and options.navigate for where the browser goes, which is window.location.assign by default.

ConsentPage.vue
<script setup lang="ts">
import { McpConsent, useAuth, useSupatype } from "@supatype/vue"
import { computed } from "vue"
import MyLogin from "./MyLogin.vue"
const client = useSupatype()
const { session, loading } = useAuth()
const authorizationId = new URLSearchParams(location.search).get("authorization_id") ?? ""
const auth = computed(() => ({ state: loading.value ? "loading" : session.value ? "signed-in" : "signed-out" } as const))
</script>
<template>
<McpConsent :request="{ oauth: client.auth.oauth, authorizationId, serverName: 'Acme Tasks' }" :auth="auth">
<template #sign-in><MyLogin /></template>
</McpConsent>
</template>

The sign-in goes in the sign-in slot.

ConsentPage.svelte
<script lang="ts">
import { createAuth, getSupatypeClient } from "@supatype/svelte"
import McpConsent from "@supatype/svelte/mcp-consent"
import MyLogin from "./MyLogin.svelte"
const client = getSupatypeClient()
const { session, loading } = createAuth()
const authorizationId = new URLSearchParams(location.search).get("authorization_id") ?? ""
const state = $derived($loading ? "loading" : $session ? "signed-in" : "signed-out")
</script>
<McpConsent request={{ oauth: client.auth.oauth, authorizationId, serverName: "Acme Tasks" }} auth={{ state }}>
{#snippet signIn()}<MyLogin />{/snippet}
</McpConsent>

The sign-in goes in the signIn snippet. The component is shipped as a .svelte file on its own path, @supatype/svelte/mcp-consent, so your app’s Svelte plugin compiles it with the rest of your code and the rest of the package still imports in plain Node.

ConsentPage.tsx
import { McpConsent, createAuth, useSupatype } from "@supatype/solid"
import { MyLogin } from "./MyLogin"
export function ConsentPage() {
const client = useSupatype()
const { session, loading } = createAuth()
const authorizationId = new URLSearchParams(location.search).get("authorization_id") ?? ""
const state = () => (loading() ? "loading" : session() ? "signed-in" : "signed-out")
return (
<McpConsent
request={{ oauth: client.auth.oauth, authorizationId, serverName: "Acme Tasks" }}
auth={{ get state() { return state() } }}
signIn={() => <MyLogin />}
/>
)
}

The sign-in is the signIn function. The Solid screen is real Solid JSX: the package ships a DOM build for the browser, a server build for Node, and the JSX source under the solid condition, so it renders under SolidStart server rendering as well.

React Native

App.tsx
import * as SecureStore from "expo-secure-store"
import * as WebBrowser from "expo-web-browser"
import * as Linking from "expo-linking"
import { SupatypeProvider } from "@supatype/react"
import { createNativeClient } from "@supatype/react-native"
import { AuthGate, LoginForm, OAuthButton } from "@supatype/react-native-auth"
const client = createNativeClient({
url: process.env.EXPO_PUBLIC_SUPATYPE_URL!,
anonKey: process.env.EXPO_PUBLIC_SUPATYPE_ANON_KEY!,
secureStore: SecureStore,
})
const redirectTo = Linking.createURL("auth/callback")
export default function App() {
return (
<SupatypeProvider client={client}>
<AuthGate fallback={<><LoginForm /><OAuthButton provider="google" redirectTo={redirectTo} webBrowser={WebBrowser} /></>}>
<>{/* your signed-in screens */}</>
</AuthGate>
</SupatypeProvider>
)
}

AuthGate renders its children only when there is a session, and fallback otherwise. The native OAuthButton uses PKCE and opens the provider in expo-web-browser. Wrap the tree in AuthThemeProvider to change colours and spacing.

MCP connections and keys

The auth server is also the sign-in for your app’s app MCP: an agent that connects to /mcp/v1 is sent to the auth server to authorize, and the person who approves it is one of your users. Nothing here needs a Studio role.

The auth server serves a default approval page at /auth/v1/oauth/consent on the project’s API URL. It signs the person in with the sign-in methods the project has switched on, shows which agent is asking and the address it will return to, and shows whether the agent may only read or also write (the mcp:read and mcp:write scopes). Approve or Deny sends the person back to the agent. The page is the same on a self-hosted stack and on Supatype Cloud.

To approve on your own domain, set mcp.app.consentUrl in supatype.config.ts and the auth server sends app MCP approvals there instead. Studio’s own MCP approvals keep going to Studio’s page. See Sign-in and approval for the setting.

A page of your own does three things: it reads the approval request the auth server hands it, signs the person in if they are not, and posts their choice. <McpConsent /> in @supatype/react does all three, and the same calls are available as auth.oauth in @supatype/client: getAuthorization(id), approve(id) and deny(id), for an app that is not React.

Connected agents

A signed-in user can list the agents they have approved and cut one off. auth.oauth.listGrants() returns them and auth.oauth.revokeGrant(clientId) removes one. A revoked agent holds a token for at most 10 more minutes, and its refresh token stops working at once.

Connected apps in your app

In a React app, <ConnectedApps /> from @supatype/react is the screen for both lists. It shows the agents the signed-in user has approved, with the access each has and when it was approved, and a Revoke button for each. Under it, the user’s API keys, with their access, when each was made and last used, and Revoke. A user can make a new key there by naming it and choosing whether it can only read or also change data. The key is shown once, with a Copy button and a warning that it will not be shown again. Each list has its own loading, empty and error state, so one failing does not hide the other. Put it on a settings page inside a <SupatypeProvider>:

Settings.tsx
// docs:no-check (a fragment: SupatypeProvider is already around your app)
import { ConnectedApps } from "@supatype/react"
export function Settings() {
return <ConnectedApps />
}

Outside a provider, pass the client’s auth object: <ConnectedApps api={client.auth} />. Vue, Svelte and Solid have the same screen, with the same text and the same choices. Each takes the client’s auth object as api.

Settings.vue
<script setup lang="ts">
import { ConnectedApps, useSupatype } from "@supatype/vue"
const client = useSupatype()
</script>
<template>
<ConnectedApps :api="client.auth" />
</template>
Settings.svelte
<script lang="ts">
import { getSupatypeClient } from "@supatype/svelte"
import ConnectedApps from "@supatype/svelte/connected-apps"
const client = getSupatypeClient()
</script>
<ConnectedApps api={client.auth} />
Settings.tsx
import { ConnectedApps, useSupatype } from "@supatype/solid"
export function Settings() {
const client = useSupatype()
return <ConnectedApps api={client.auth} />
}

The Vue, Svelte and Solid screens are unstyled: semantic markup under stable class names (supatype-connected-apps, with an element name after __) and no inline styles, so they work under a strict Content Security Policy. Style them with your own CSS. The Svelte screen is a .svelte file on its own path, @supatype/svelte/connected-apps, for the same reason as McpConsent. In another framework, build the same page on auth.oauth.listGrants(), auth.oauth.revokeGrant() and auth.mcpKeys.

Per-user keys

A user who wants to connect a script, or an agent that has no browser, can make a key instead. The user’s own session calls these routes on the auth server:

RouteDoes
POST /auth/v1/user/mcp-keysMakes a key from { "name": "...", "scopes": ["mcp:read"] }. The answer holds the key, which starts with stmcp_. It is shown once and only a hash of it is stored
GET /auth/v1/user/mcp-keysLists the user’s keys, with each one’s name, scopes, creation time and last use. Never the key itself
DELETE /auth/v1/user/mcp-keys/{id}Revokes a key. A revoked key makes no new connections, and one already connected stops within 5 minutes

A key is sent as the bearer token to /mcp/v1 and is valid nowhere else: the REST, storage and auth APIs refuse it. The agent acts as the user who made it, under your access rules, and its calls are logged with the key’s id as the client. Deleting the user deletes their keys.

Configuration

Email delivery

Confirmation, magic link and reset emails go through the email block in supatype.config.ts:

supatype.config.ts
email: {
provider: "smtp", // "console" | "smtp" | "resend" | "ses"
smtp: { host: "smtp.example.com", port: 587, user: "apikey", pass: process.env.SMTP_PASS, admin_email: "no-reply@example.com" },
},

On a self-hosted stack, for Resend set email.resend_api_key and email.resend_from in the email block above (a value set by hand in .env is replaced from supatype.config.ts). For SES set email.ses_from; credentials come from the environment’s AWS configuration.

On Supatype Cloud there is no .env and no ambient AWS configuration, so SES takes all of its settings from the email block, and a push that leaves one out is refused:

supatype.config.ts
email: {
provider: "ses",
ses_from: "no-reply@example.com", // required: the sender address, verified in SES
ses_access_key_id: env("SES_ACCESS_KEY_ID"), // required: name an environment variable, never the key itself
ses_secret_access_key: env("SES_SECRET_ACCESS_KEY"), // required, the same way
ses_region: "eu-west-2", // optional
},

Without ses_from the server cannot send, so mail would be dropped while requests still succeed. That is why Cloud refuses the push and names email.ses_from.

Email sign-in and confirmation

Two keys under auth.email in supatype.config.ts decide what email-and-password sign-in does:

supatype.config.ts
auth: {
email: { enabled: true, enableConfirmations: true },
},
  • enabled, default true. false turns email-and-password sign-up and sign-in off at the auth server, and magic links and password recovery with them, for a project that signs in only with OAuth or SAML.
  • enableConfirmations: whether a new sign-up has to click a link in an email before it can sign in. Unset, a self-hosted stack (supatype self-host compose) sends the link and local dev, Docker or native, confirms the sign-up at once. true or false sets it for every stack.

supatype dev and supatype self-host compose pass both to the auth server on every start, as SUPATYPE_EXTERNAL_EMAIL_ENABLED and SUPATYPE_MAILER_AUTOCONFIRM. Either variable set in the project’s .env wins over the config for that stack; the CLI never writes them there. Studio shows each under Authentication > Configuration, with the key that sets it.

Rate limits

auth.rateLimits caps how often one client may call the auth server:

supatype.config.ts
auth: {
rateLimits: { verify: 10, otp: 5 },
},

Each limit except smsSent counts requests per client IP address. The address is the one the gateway forwards: Kong writes X-Real-IP from the connection and replaces any value the client sent, so a client cannot pick its own. The server believes a forwarded address only on a request that carries the project’s forwarding secret, which Kong adds and no client holds. Any other request counts against the address of its connection, whatever St-Forwarded-For, X-Real-IP or X-Forwarded-For it carries, and the IP recorded in audit logs follows the same rule. A client over a limit gets 429 with error code over_request_rate_limit until the window lets it in again.

KeyWhat it counts, per clientWindowDefault
otpSign-up and sign-in requests: /signup (not anonymous), /otp, magic links, password recovery, /resend and updating the signed-in user. Each of these counts on its own. It counts requests, not emails5 minutes30
verifyRequests to /verify, which checks the code or link from an email or SMS, whether the code is right or not5 minutes30
tokenRefreshRequests to /token: password sign-in, refreshing a session and the other grants5 minutes150
ssoRequests that start a SAML sign-in5 minutes30
mfaMulti-factor challenges, and verifies, each counted on its own1 minute15
anonymousUsersAnonymous sign-ins1 hour30
smsSentSMS messages the server sends, across every client together1 hour30

A limit of N lets one client make N requests at once, and then one more each time the window divided by N passes. Every per-client limit works that way, over its own window: a limit of 3 lets one client make 3 requests at once, never more. A limit below 1 still lets one through. How many emails the server sends an hour is a separate limit: SUPATYPE_RATE_LIMIT_EMAIL_SENT on self-host, and the platform’s on Cloud.

On self-host each key renders as a SUPATYPE_RATE_LIMIT_* variable for the server (mfa as SUPATYPE_MFA_RATE_LIMIT_CHALLENGE_AND_VERIFY), and a value in .env wins. Behind a proxy in front of Kong, Kong sees the proxy’s address, so every client would share one count: set SUPATYPE_RATE_LIMIT_HEADER in .env to a header that proxy writes from the connection, and only if nothing else can reach Kong.

The forwarding secret is SUPATYPE_FORWARDING_SECRET in .env. supatype init generates it, and a project that predates it gets one on its next dev or self-host command. It is given to the server (as SUPATYPE_SECURITY_FORWARDING_SECRET), to Kong and to the functions worker, and to nothing else: the worker removes it from the environment before it loads your functions, so function code cannot read it. When a function calls the project’s own address, the worker passes on the end user’s address with it, so a function that signs a user in is counted against that user and not against the worker. Under Docker the worker reaches Kong on a second port, 8100, that is never published to the host: Kong leaves the two headers alone there, where it removes them on the public port, and adds no secret of its own, so code that reaches 8100 without the secret is still counted against its own connection. Keep it out of version control like the other secrets in .env, and never log it. A server with no secret set believes forwarded addresses from any sender, as before, and says so once when it starts.

Environment variables

The server reads the project’s .env when it starts, so SUPATYPE_* auth variables placed there take effect after a restart. In the Docker stacks, a few values are set by the generated Compose file and are read from the plain names shown.

VariableWhat it does
JWT_SECRETSigns every token. Required for self-host. Change it and every issued token, including the anon and service role keys, stops working
ANON_KEY, SERVICE_ROLE_KEYKeys signed with JWT_SECRET. supatype keys --write generates them
SITE_URLSelf-host: your app’s URL, the default place users land after confirming or signing in
SUPATYPE_URI_ALLOW_LISTOther URLs redirectTo may point at, comma-separated
DISABLE_SIGNUP (self-host), SUPATYPE_DISABLE_SIGNUP (native dev)true stops new sign-ups
SUPATYPE_EXTERNAL_EMAIL_ENABLEDfalse turns email-and-password sign-in off. Set from auth.email.enabled; a value in .env wins
SUPATYPE_MAILER_AUTOCONFIRMtrue skips email confirmation. Set from auth.email.enableConfirmations: when that is unset, off in self-host and on in dev. A value in .env wins: set it there and restart the stack
SUPATYPE_EXTERNAL_<PROVIDER>_*OAuth providers, see above
SUPATYPE_EXTERNAL_ANONYMOUS_USERS_ENABLEDAllow anonymous sign-in
SUPATYPE_EXTERNAL_EMAIL_MAGIC_LINK_ENABLEDfalse turns magic links off
SUPATYPE_PASSWORD_MIN_LENGTHMinimum password length, at least 6
SUPATYPE_EXTERNAL_PHONE_ENABLED, SUPATYPE_SMS_PROVIDERPhone sign-in. The provider is twilio, twilio_verify, messagebird, textlocal or vonage

To create users from a seed file, see Seeding users.