Phone Authentication is another method of Authentication in Supabase. The Kotlin library provides a easy way to integrate Phone Auth in your App.
Before you can try out Phone Auth, you have to setup a SMS provider in your Supabase Dashboard. There you can also customize the SMS message and the OTP, the user receives.
After you setup everything, you can easily create new users with a phone number:
val user = client.gotrue.signUpWith(Phone) {
phoneNumber = "+12345678912"
password = "password"
}
If you enabled phone confirmations, the user should receive a phone message with an OTP. You can use this OTP to confirm the sign up and login:
client.gotrue.verifyPhoneOtp(
type = OtpType.Phone.SMS,
phoneNumber = "+123456789",
token = "123456"
)
If this was successful, the user is logged in!
Phone Authentication allows passwordless login, allowing users to login with just their phone number:
client.gotrue.sendOtpTo(Phone) {
phoneNumber = "+123456789"
}
Once received, verify the OTP:
client.gotrue.verifyPhoneOtp(
type = OtpType.Phone.SMS,
phoneNumber = "+123456789",
token = "123456"
)
Phone login with a password can also be done:
client.gotrue.loginWith(Phone) {
phoneNumber = "+1234567891"
password = "password"
}