Cannot Use Both Email and Phone Providers Simultaneously
I am trying to register a user using both email and phone authentication in Flutter app with Supabase, but encountering the following error:
149 - assert((email != null && phone == null) || (email == null && phone != null), 150 - 'You must provide either an email or phone number'); This error arises because Supabase currently enforces a condition where only one of either email or phone is provided for user signup. However, I want to allow both email and phone parameters to be provided simultaneously, as it would make verification easier before future authentications.
Is there a way to modify or extend the logic in Supabase to support both email and phone authentication providers during signup? and their provider must be working on login seprately.
pos: I am using twilio provider for phone
This error arises because Supabase currently enforces a condition where only one of either email or phone is provided for user signup. However, I want to allow both email and phone parameters to be provided simultaneously, as it would make verification easier before future authentications.
Hey!
Thanks for the query, unfortunately this is right - we only allow signup with one method at a time (e.g. signUp({phone, password}) or signUp({email,password}) You can create an account with email and add a phone number via updateUser though or vice versa.
and their provider must be working on login seprately.
To clarify, is the team hoping to have two separate accounts? (e.g. email would be one account, and phone on another). For that scenario it's possible to call sign up twice (first with phone, second with email) and there should be two separate accounts.
Let us know
@J0 Can you please share an example?
Hi @muddasirAlgo, this is how I am resolving this issue in my node.js app. I hope it helps.
const { data: { user } } = await supabase.auth.signUp({
email: userData.email,
password: userData.password,
});
await supabase.auth.admin.updateUserById(user.id, { phone: userData.phone });
@J0 Say we want to signup user with email but also link their phone number to the account. For this say initially with signup user with email otp, now when trying to verify phone, a separate entry is created by supabase, so we cannot add this phone number to exisiting email entry (since we cannot create duplicate entry in a emal/phone column).
What is the solution here to have user link their verified-email and verified-phone to the same user UID. The example shared by @ab-elhaddad, has the issue that phone is not verified but updated.
Appreciate any insight!
cc: @cstockton @hf
@MehulDokania When you update the user with a new phone number it should send an SMS confirmation unless you have "SMS Auto-confirm" enabled in your phone provider setting: https://github.com/supabase/auth/blob/master/internal/api/user.go#L250
You will then need to call the verify endpoint.
const { data, error } = await supabase.auth.verifyOtp({ phone, token, type: 'phone_change'})
The token should be provided by the user from the phone confirmation sms we sent. Once verified the user should be able to signin with either phone or email.