Swift: Sign in a user through OTP
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 the user doesn't exist, signInWithOTP()
will signup the user instead. To restrict this behavior, you can set shouldCreateUser
to `false``.
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
.
See redirect URLs and wildcards to add additional redirect URLs to your project.
Magic links and OTPs share the same implementation. To send users a one-time code instead of a magic link, modify the magic link email template to include \{\{ .Token \}\}
instead of \{\{ .ConfirmationURL \}\}
.
See our Twilio Phone Auth Guide for details about configuring WhatsApp sign in.
Parameters email (Optional) One of `email` or `phone` must be provided.
phone (Optional) One of `email` or `phone` must be provided.
redirectTo (Optional) Only for email signups. The redirect URL embedded in the email link. Must be a configured redirect URL for your Supabase instance.
channel (Optional) The channel to use for sending messages. Only for phone signups.
shouldCreateUser (Optional) Whether to create the user if they don't already exist. Defaults to true.
data (Optional) A custom data object to store additional user metadata.
captchaToken (Optional) undefined
Examples Sign in with email try await supabase.auth.signInWithOTP(
email: "example@email.com",
redirectTo: URL(string: "my-app-scheme://")!
)
Sign in with SMS OTP try await supabase.auth.signInWithOTP(phone: "+13334445555")
Sign in with WhatsApp OTP try await supabase.auth.signInWithOTP(
phone: "+13334445555",
channel: "whatsapp"
)