Skip to content

Platform

Phone and anonymous sign-in

Tested with:supabase-js 2 · @supabase/auth-js 2.117

Turn on Anonymous sign-ins in Platform services → Auth → Providers. Then supabase.auth.signInAnonymously() creates a user with no email or phone; its access token carries is_anonymous: true and the authenticated role, so your policies can treat it differently:

SQL
create policy "permanent users only" on orders
as restrictive for insert to authenticated
with check ((auth.jwt() ->> 'is_anonymous')::boolean is not true);

An anonymous user becomes a permanent user, keeping its id and data, when it:

  • adds an email (updateUser({ email }), then the confirmation link or code),
  • adds a phone (updateUser({ phone }), then verifyOtp({ phone, token, type: "phone_change" })), or
  • links a social provider (linkIdentity).

A password can be set only after the email or phone is verified. Limits: sign-ins per client IP per hour (per_ip_per_hour, 30 by default), CAPTCHA when the project has it (require_captcha refuses anonymous sign-ins while CAPTCHA is off), and anonymous users count as monthly active users like any other; when a project with a hard MAU cap reaches 90% of it, new anonymous users are refused first.

app/login.ts
await supabase.auth.signInWithOtp({ phone: "+14155550100" });
await supabase.auth.verifyOtp({ phone: "+14155550100", token: code, type: "sms" });

Phone + password works too (signUp({ phone, password }), confirmed by SMS unless autoconfirm is on).

Codes go out from your account; Databasezy never sends or bills SMS. Pick the provider and paste its credential (write-only, stored in your project’s region):

sms_providerSettingsCredential
twiliotwilio_account_sid, twilio_message_service_sid (a Messaging Service SID or a sender number); optional twilio_api_baseauth token
twilio + twilio_api_basea Twilio-compatible service such as SignalWire: https://<space>.signalwire.com/api/laml (https on a public host)that service’s token
messagebirdmessagebird_originatoraccess key
vonagevonage_api_key, vonage_fromAPI secret
textlocaltextlocal_senderAPI key
shell
zb api PUT /v1/orgs/{org}/projects/<project-id>/auth/providers/phone -d '{
"enabled": true,
"secret": "<twilio auth token>",
"phone": { "sms_provider": "twilio", "twilio_account_sid": "AC...", "twilio_message_service_sid": "MG...",
"allowed_countries": ["1", "44"] }
}'

Twilio can also deliver over WhatsApp (channel: "whatsapp"). Instead of a provider you can deliver codes yourself with a send_sms auth hook: a Postgres function or an HTTPS endpoint receives {"user": {..., "phone": "14155550100"}, "sms": {"otp": "123456"}}. Hooks and providers also deliver MFA phone codes.

test_otp maps up to 20 numbers to fixed codes ({"15555550100": "246810"}): no SMS is sent to them, which is what you want for app-store reviews and end-to-end tests. Without a provider or a hook, only test numbers can sign in.

SettingDefault
allowed_countries (calling-code prefixes)every country
max_frequency between two codes to a number60 s
max_per_number_per_hour5
max_per_ip_per_hour10
max_numbers_per_ip_per_hour (distinct numbers)5
max_per_hour / max_per_day (project)100 / 1000

Codes are otp_length digits (6), expire after otp_expiry (60 s) and are single use. A blocked country and a breached cap are security events in your audit log.