Passwordless email sign-in
Let users sign in with only their email address, by clicking a magic link or entering a one-time password (OTP).
Overview
Supabase Auth offers two passwordless sign-in methods that use the user's email address:
- Magic link uses the default email templates.
- OTP has you edit the email templates to send a code instead.
Both methods use the client library's "sign in with OTP" call, which sends a magic link by default. The email template decides whether the user gets a link or a code.
With magic link
Magic links are a form of passwordless sign-in where users click a link sent to their email address. Magic links work only with email addresses, and each link works only once.
Enable magic links
Email authentication methods, including magic links, are enabled by default.
Configure the Site URL and any additional redirect URLs. Only these URLs are allowed as redirect destinations after the user clicks a magic link. You can change the URLs on the URL Configuration page for hosted projects, in your config file for local development, or in the .env configuration file for self-hosted Supabase.
By default, a user can request a magic link only once every 60 seconds, and each link expires after 1 hour.
To test magic links without hitting email limits, see Test auth flows.
Sign in with a magic link
Call the "sign in with OTP" method from the client library.
If the user hasn't signed up, the call signs them up by default. To prevent this, set the shouldCreateUser option to false.
async function () { const { , } = await ..({ : 'valid.email@supabase.io', : { // set this to false if you do not want the user to be automatically signed up : false, : 'https://example.com/welcome', }, })}import { makeRedirectUri } from 'expo-auth-session'const redirectTo = makeRedirectUri()const { error } = await supabase.auth.signInWithOtp({ email: 'valid.email@supabase.io', options: { emailRedirectTo: redirectTo, },})To handle the redirect in your app, see Native mobile deep linking.
Future<void> signInWithEmail() async { await supabase.auth.signInWithOtp(email: 'valid.email@supabase.io');}try await supabase.auth.signInWithOTP( email: "valid.email@supabase.io", redirectTo: URL(string: "https://example.com/welcome"), // set this to false if you do not want the user to be automatically signed up shouldCreateUser: false)suspend fun signInWithEmail() { supabase.auth.signInWith(OTP) { email = "valid.email@supabase.io" }}response = supabase.auth.sign_in_with_otp({ 'email': 'valid.email@supabase.io', 'options': { # set this to false if you do not want the user to be automatically signed up 'should_create_user': False, 'email_redirect_to': 'https://example.com/welcome', },})var options = new SignInOptions { RedirectTo = "https://example.com/welcome" };var didSendMagicLink = await supabase.Auth.SendMagicLink("valid.email@supabase.io", options);The implicit flow needs no further setup.
Use the PKCE flow
If you use the PKCE flow, edit the Magic link or OTP email template to send a token hash:
<h2>Sign in to your account</h2><p>Use this link to sign in to your account:</p><p><a href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=email">Sign in</a></p>At the /auth/confirm endpoint, exchange the hash for the session:
const { } = await ..({ : 'hash', : 'email',})With OTP
Email one-time passwords (OTP) are a form of passwordless sign-in where users enter a six-digit code sent to their email address.
Enable email OTP
Email authentication methods, including email OTPs, are enabled by default.
The email template decides whether a user gets a link or a code. Which template Auth sends depends on the user:
- A user who has already confirmed their email address gets the Magic link or OTP template.
- When email confirmations are on, a user signing in with a new or unconfirmed email address gets the Confirm sign up template instead, because the sign-in call also creates their account.
To send every user an OTP instead of a magic link, add the {{ .Token }} variable to both templates:
-
Edit the Magic link or OTP template to include
{{ .Token }}, for example:<h2>One time login code</h2><p>Please enter this code: {{ .Token }}</p> -
Edit the Confirm sign up template to include
{{ .Token }}the same way.
If either template still contains a link, users can still sign in by clicking it instead of entering the code. For how confirmations work and how to edit templates outside the Dashboard, see the Email templates guide.
By default, a user can request an OTP only once every 60 seconds, and each OTP expires after 1 hour. To change the expiry, go to Authentication > Sign In / Providers > Auth Providers > Email > Email OTP expiration.
Avoid an expiry longer than 86,400 seconds (one day). You can set one only through the Management API. Before going to production, read the security recommendations.
Changing Email OTP expiration also changes how long magic links and other email links stay valid, including confirmation, password recovery, email change, and invitation links.
If users see an expired-token error, see OTP verification failures.
Sign in with email OTP
Signing in with an OTP takes two calls: one sends a code to the user's email address, and one verifies the code they enter.
Step 1: Send the user an OTP code
Get the user's email and call the "sign in with OTP" method from your client library.
If the user hasn't signed up, the call signs them up by default. To prevent this, set the shouldCreateUser option to false.
const { , } = await ..({ : 'valid.email@supabase.io', : { // set this to false if you do not want the user to be automatically signed up : false, },})Future<void> signInWithEmailOtp() async { await supabase.auth.signInWithOtp(email: 'valid.email@supabase.io');}try await supabase.auth.signInWithOTP( email: "valid.email@supabase.io", // set this to false if you do not want the user to be automatically signed up shouldCreateUser: false)suspend fun signInWithEmailOtp() { supabase.auth.signInWith(OTP) { email = "valid.email@supabase.io" }}response = supabase.auth.sign_in_with_otp({ 'email': 'valid.email@supabase.io', 'options': { # set this to false if you do not want the user to be automatically signed up 'should_create_user': False, },})await supabase.Auth.SendMagicLink("valid.email@supabase.io");If the request is successful, you receive a response with error: null and a data object where both user and session are null. Tell the user to check their inbox.
{ "data": { "user": null, "session": null }, "error": null}Step 2: Verify the OTP to create a session
Provide an input field for the user to enter their one-time code.
Call the "verify OTP" method from your client library with the user's email address, the code, and a type of email:
const { : { }, ,} = await ..({ : 'email@example.com', : '123456', : 'email',})try await supabase.auth.verifyOTP( email: email, token: "123456", type: .email)supabase.auth.verifyEmailOtp(type = OtpType.Email.EMAIL, email = "email", token = "151345")response = supabase.auth.verify_otp({ 'email': email, 'token': '123456', 'type': 'email',})var session = await supabase.Auth.VerifyOTP("email@example.com", "123456", EmailOtpType.Email);If successful, the user is now signed in, and you receive a valid session that looks like:
{ "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjI3MjkxNTc3LCJzdWIiOiJmYTA2NTQ1Zi1kYmI1LTQxY2EtYjk1NC1kOGUyOTg4YzcxOTEiLCJlbWFpbCI6IiIsInBob25lIjoiNjU4NzUyMjAyOSIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6InBob25lIn0sInVzZXJfbWV0YWRhdGEiOnt9LCJyb2xlIjoiYXV0aGVudGljYXRlZCJ9.1BqRi0NbS_yr1f6hnr4q3s1ylMR3c1vkiJ4e_N55dhM", "token_type": "bearer", "expires_in": 3600, "refresh_token": "LSp8LglPPvf0DxGMSj-vaQ", "user": {...}}Next steps
To keep going, use these pages:
- Send emails with custom SMTP: send sign-in emails from your own provider before going to production.
- Email templates: customize the content of every email Auth sends.
- Test auth flows: test sign-in without hitting email rate limits.
- Phone sign-in: send one-time passwords by SMS instead of email.