Skip to main content
Version: v2 RC

signInWithOtp()

Log in a user using magiclink or a one-time password (OTP). If the {{ .ConfirmationURL }} variable is specified in the email template, a magiclink will be sent. If the {{ .Token }} variable is specified in the email template, an OTP will be sent. If you're using phone sign-ins, only an OTP will be sent. You won't be able to send a magiclink for phone sign-ins.

const { data, error } = await supabase.auth.signInWithOtp({
email: 'example@email.com',
})

Parameters

  • SignInWithPasswordlessCredentialsrequiredreflection | reflection

    No description provided.

      Properties
    • objectrequiredobject

      No description provided.

        Properties
      • phonerequiredstring

        The user's phone number.

      • optionsoptionalobject

        No description provided.

          Properties
        • captchaTokenoptionalstring

          Verification token received when the user completes the captcha on the site.

        • shouldCreateUseroptionalboolean

          If set to false, this method will not create a new user. Defaults to true.

    • objectrequiredobject

      No description provided.

        Properties
      • emailrequiredstring

        The user's email address.

      • optionsoptionalobject

        No description provided.

          Properties
        • captchaTokenoptionalstring

          Verification token received when the user completes the captcha on the site.

        • emailRedirectTooptionalstring

          The redirect url embedded in the email link

        • shouldCreateUseroptionalboolean

          If set to false, this method will not create a new user. Defaults to true.

Notes

  • Requires either an email or phone number.
  • This method is used for passwordless sign-ins where a OTP is sent to the user's email or phone number.
  • If you're using an email, you can configure whether you want the user to receive a magiclink or a OTP.
  • If you're using phone, you can configure whether you want the user to receive a OTP.
  • The magic link's destination URL is determined by the SITE_URL. You can modify the SITE_URL or add additional redirect urls in your project.

Examples

Sign in with email.

The user will be sent an email which contains either a magiclink or a OTP or both. By default, a given user can only request a OTP once every 60 seconds.

const { data, error } = await supabase.auth.signInWithOtp({
email: 'example@email.com',
})

Sign in with SMS OTP.

The user will be sent a SMS which contains a OTP. By default, a given user can only request a OTP once every 60 seconds.

const { data, error } = await supabase.auth.signInWithOtp({
phone: '+13334445555',
})