--- title: 'Passwordless email sign-in' description: 'Let users sign in to your app with a magic link or a one-time code sent to their email address, and set up the Auth email templates that deliver each one.' --- 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](#with-magic-link) uses the default email templates. - [OTP](#with-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 [#enabling-magic-link] Email authentication methods, including magic links, are enabled by default. Configure the Site URL and any additional [redirect URLs](/docs/guides/auth/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](/dashboard/project/_/auth/url-configuration) for hosted projects, in your [config file](/docs/guides/local-development/cli/config#auth.additional_redirect_urls) for local development, or in the `.env` configuration file for [self-hosted Supabase](/docs/guides/self-hosting/docker). By default, a user can request a magic link only once every auth.rate_limits.magic_link.period, and each link expires after auth.rate_limits.magic_link.validity. To test magic links without hitting email limits, see [Test auth flows](/docs/guides/auth/testing-auth-flows). ### Sign in with a magic link [#signing-in-with-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`. ```js import { createClient } from '@supabase/supabase-js' const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...') // ---cut--- async function signInWithEmail() { const { data, error } = await supabase.auth.signInWithOtp({ email: 'valid.email@supabase.io', options: { // set this to false if you do not want the user to be automatically signed up shouldCreateUser: false, emailRedirectTo: 'https://example.com/welcome', }, }) } ``` ```ts 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](/docs/guides/auth/native-mobile-deep-linking). <$Show if="sdk:dart"> ```dart Future signInWithEmail() async { await supabase.auth.signInWithOtp(email: 'valid.email@supabase.io'); } ``` <$Show if="sdk:swift"> ```swift 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 ) ``` <$Show if="sdk:kotlin"> ```kotlin suspend fun signInWithEmail() { supabase.auth.signInWith(OTP) { email = "valid.email@supabase.io" } } ``` <$Show if="sdk:python"> ```python 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', }, }) ``` <$Show if="sdk:csharp"> ```c# 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](/docs/guides/auth/auth-email-templates) to send a token hash: ```html

Sign in to your account

Use this link to sign in to your account:

Sign in

``` At the `/auth/confirm` endpoint, exchange the hash for the session: ```js import { createClient } from '@supabase/supabase-js' const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...') // ---cut--- const { error } = await supabase.auth.verifyOtp({ token_hash: 'hash', type: '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 [#enabling-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: 1. Edit the [**Magic link or OTP** template](/dashboard/project/_/auth/templates/magic-link-or-otp) to include `{{ .Token }}`, for example: ```html

One time login code

Please enter this code: {{ .Token }}

``` 2. Edit the [**Confirm sign up** template](/dashboard/project/_/auth/templates/confirm-sign-up) 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](/docs/guides/auth/auth-email-templates). By default, a user can request an OTP only once every auth.rate_limits.otp.period, and each OTP expires after auth.rate_limits.otp.validity. 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](/docs/reference/api/v1-update-auth-service-config). Before going to production, read the [security recommendations](/docs/guides/security/production-checklist#auth). Changing **Email OTP expiration** also changes how long magic links and other email links stay valid, including confirmation, password recovery, email change, and [invitation](/docs/guides/auth/users#inviting-users) links. If users see an expired-token error, see [OTP verification failures](/kb/troubleshooting/otp-verification-failures-token-has-expired-or-otp_expired-errors-5ee4d0). ### Sign in with email OTP [#signing-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`. ```js import { createClient } from '@supabase/supabase-js' const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...') // ---cut--- const { data, error } = await supabase.auth.signInWithOtp({ email: 'valid.email@supabase.io', options: { // set this to false if you do not want the user to be automatically signed up shouldCreateUser: false, }, }) ``` <$Show if="sdk:dart"> ```dart Future signInWithEmailOtp() async { await supabase.auth.signInWithOtp(email: 'valid.email@supabase.io'); } ``` <$Show if="sdk:swift"> ```swift 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 ) ``` <$Show if="sdk:kotlin"> ```kotlin suspend fun signInWithEmailOtp() { supabase.auth.signInWith(OTP) { email = "valid.email@supabase.io" } } ``` <$Show if="sdk:python"> ```python 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, }, }) ``` <$Show if="sdk:csharp"> ```c# 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. ```json { "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`: ```js import { createClient } from '@supabase/supabase-js' const supabase = createClient('https://your-project-id.supabase.co', 'sb_publishable_...') // ---cut--- const { data: { session }, error, } = await supabase.auth.verifyOtp({ email: 'email@example.com', token: '123456', type: 'email', }) ``` <$Show if="sdk:swift"> ```swift try await supabase.auth.verifyOTP( email: email, token: "123456", type: .email ) ``` <$Show if="sdk:kotlin"> ```kotlin supabase.auth.verifyEmailOtp(type = OtpType.Email.EMAIL, email = "email", token = "151345") ``` <$Show if="sdk:python"> ```python response = supabase.auth.verify_otp({ 'email': email, 'token': '123456', 'type': 'email', }) ``` <$Show if="sdk:csharp"> ```c# 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: ```json { "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](/docs/guides/auth/auth-smtp): send sign-in emails from your own provider before going to production. - [Email templates](/docs/guides/auth/auth-email-templates): customize the content of every email Auth sends. - [Test auth flows](/docs/guides/auth/testing-auth-flows): test sign-in without hitting email rate limits. - [Phone sign-in](/docs/guides/auth/phone-login): send one-time passwords by SMS instead of email.