Email & Password
Email and password is the most common authentication method. Supatype handles sign-up, email confirmation, sign-in, and password reset out of the box.
Sign up
const { data, error } = await supatype.auth.signUp({ email: "alice@example.com", password: "strongpassword123",})Whether the user must confirm their email before signing in is auth.email.enableConfirmations in
supatype.config.ts. When it is unset:
- Local dev (
supatype dev, Docker or native) confirms a sign-up at once:signUpreturns a session straight away and no confirmation email is sent. - A self-hosted stack (
supatype self-host compose) sends a confirmation link:signUpreturns a user but no session, and the user can sign in once they have clicked the link. Configure email delivery (theemailblock insupatype.config.ts) before you open sign-up.
Choose for every stack
Set the key to true to require confirmation on every stack, local dev included (to try the
confirmation email locally), or to false to confirm every sign-up at once:
// docs:no-check (a fragment: the rest of your config stays as it is)import { defineConfig } from "@supatype/cli"
export default defineConfig({ auth: { email: { enableConfirmations: true }, },})supatype dev and supatype self-host compose pass it to the auth server as
SUPATYPE_MAILER_AUTOCONFIRM on every start. Writing SUPATYPE_MAILER_AUTOCONFIRM=false (or
true) into the project’s .env yourself and restarting the stack does the same, and a value there
wins over the config. The CLI never writes that variable into .env; the line an earlier CLI wrote
there is taken out on the next start, with a message saying so.
With confirmations on, signUp returns a user but no session, a confirmation email is sent, and
the user can sign in once they have clicked the link.
Turn email sign-in off
A project that signs in only with OAuth or SAML can turn email-and-password sign-in off:
// docs:no-check (a fragment: the rest of your config stays as it is)import { defineConfig } from "@supatype/cli"
export default defineConfig({ auth: { email: { enabled: false }, },})The auth server then refuses email sign-up, sign-in, magic links and password recovery with the
error code email_provider_disabled. supatype dev and supatype self-host compose pass it as
SUPATYPE_EXTERNAL_EMAIL_ENABLED, and a value for that variable in .env wins over the config.
Customize the confirmation email
Edit the email templates in Studio under Authentication > Email Templates. There is one
template each for signup confirmation, invites, password reset, magic links and email changes, and
they use Go template variables such as {{ .ConfirmationURL }}, {{ .Email }} and {{ .Token }}.
Save template stores the subject and HTML body in the project’s database, in the
auth.mail_templates table, one row per template type. A saved template is used by every auth
server replica and survives a restart, and it wins over a template configured with the auth
server’s SUPATYPE_MAILER_TEMPLATES_* and SUPATYPE_MAILER_SUBJECTS_* variables. Studio shows
when a saved edit is in force (“Saved edit in force since …”); Reset to default deletes it,
and the configured template, or the built-in one when none is configured, is used again. An edit
saved on one replica reaches the emails the others send within ten seconds.
Before 0.7.0 a saved template lived only in the memory of the auth server that received it, so a restart, or another replica, quietly went back to the configured template.
The same operations are on the auth admin API, with the service role key:
GET, PUT (a JSON body with subject and body, both required) and DELETE on
/auth/v1/admin/template/<type>, where <type> is confirmation, invite, recovery,
magic_link (or magiclink) or email_change. The GET answer carries saved and, when it is
true, saved_at.
Sign in
const { data, error } = await supatype.auth.signInWithPassword({ email: "alice@example.com", password: "strongpassword123",})
if (error) { console.error("Sign in failed:", error.message) return}
// data.session contains the JWT// data.user contains the user objectconsole.log("Signed in as:", data.user?.email)Password requirements
Passwords must be at least 6 characters by default. The auth server can require a longer minimum
(SUPATYPE_PASSWORD_MIN_LENGTH) or particular character classes
(SUPATYPE_PASSWORD_REQUIRED_CHARACTERS), but these are server settings: supatype.config.ts has no
key for them, and the generated stack does not set them.
Password reset
Send a reset email
const { error } = await supatype.auth.resetPasswordForEmail( "alice@example.com", { redirectTo: "https://myapp.com/reset-password", })Handle the reset callback
When the user clicks the reset link, they are redirected to your app with a session in the URL. In
a browser the client signs them in from it as it starts, removes the tokens from the address bar
and emits PASSWORD_RECOVERY. Wait for that to finish, then update the password:
// On your /reset-password pageconst { error: linkError } = await supatype.auth.initialize()
if (linkError) { console.error("Reset link refused:", linkError.message)} else { const { data, error } = await supatype.auth.updateUser({ password: "newstrongpassword456", })}With detectSessionInUrl: false, or outside a browser (a React Native deep link), call
supatype.auth.getSessionFromUrl(url) with the link instead.
Server-side validation
Passwords are hashed with bcrypt before storage; the plaintext is never stored. Sign-in attempts
share the token endpoint’s per-IP rate limit (SUPATYPE_RATE_LIMIT_TOKEN_REFRESH, 150 requests
per five minutes by default). The auth server applies per-IP limits only when it can read the
caller’s IP from the header SUPATYPE_RATE_LIMIT_HEADER names (such as X-Forwarded-For), and the
generated stack does not set it.
Email rate limits
By default, the auth server limits email sending to prevent abuse:
| Limit | Default |
|---|---|
| Emails sent by the project (confirmation, reset, magic link and the rest together) | 30 per hour |
| Interval between emails to the same user | 60 seconds |
These are the auth server’s SUPATYPE_RATE_LIMIT_EMAIL_SENT and SUPATYPE_SMTP_MAX_FREQUENCY
settings. Neither has a supatype.config.ts key.