Log on with SMS verification using Supabase
Logging on with an SMS verification code is a key feature of an application's logon system. It is also a widely accepted method for registration and logon. AnalyticDB for PostgreSQL is deeply integrated with the open source Supabase identity authentication system. In addition to the native SMS providers in Supabase, it also supports Alibaba Cloud Short Message Service (SMS). This integration helps developers build a fast and stable SMS verification logon feature. This topic describes how to use Alibaba Cloud SMS to implement SMS logon in an AnalyticDB for PostgreSQL Supabase project.
Prerequisites
You have created a Supabase project. The AnalyticDB for PostgreSQL Supabase project must be created after September 30, 2025.
You have activated Alibaba Cloud SMS and completed required tasks, such as requesting qualifications, signatures, and templates. For more information, see Quick start. Using Alibaba Cloud Short Message Service incurs fees. For more information about billing, see Billing overview.
-
You have enabled public access for your AnalyticDB for PostgreSQL Supabase project.
Procedure
Log on to the Supabase Dashboard. In the sidebar of the dashboard, click Authentication > Sign In/Providers.
Under Auth Providers, click Phone.
Configure the SMS service.
Turn on Enable Phone provider.
From the SMS provider list, select an SMS provider.
This example uses Aliyun SMS. The following table describes the configuration parameters. For information about other configuration methods, see Phone Login.
Parameter
Description
Aliyun Access Key ID
The AccessKey pair of your Alibaba Cloud account. For more information about how to obtain an AccessKey pair, see Create an AccessKey pair.
Aliyun Access Key Secret
Aliyun SMS Sign Name
The name of the signature that you requested in Alibaba Cloud SMS. For more information about how to request a signature, see Request an SMS signature.
Aliyun SMS Template Code
The name of the template that you requested in Alibaba Cloud SMS. For more information about how to request a template, see Request an SMS template.
Enable phone confirmations
If you turn on this switch, users must use a verification code to log on.
SMS OTP Expiry
The time-to-live (TTL) of the verification code, in seconds.
SMS OTP Length
The length of the verification code.
SMS Message
The template for sending text messages. Enter the content of the SMS template that corresponds to the Aliyun SMS Template Code. Replace the verification code with
{{ .Code }}.Test Phone Numbers and OTPs
The phone numbers and verification codes for testing.
Click Save. You can then use Alibaba Cloud SMS to send text messages for logon verification.
Usage
After the configuration is complete, you can use one of the following methods to log on using SMS verification.
Call using a URL
Call the sign-up API.
Log on to the Supabase Dashboard. In the upper-left corner of the dashboard, click Connect. In the pop-up window that appears, click App Frameworks to obtain the
SUPABASE_PUBLIC_URLandANON_KEY. The following code is an example.curl -X POST 'https://<SUPABASE_PUBLIC_URL>/auth/v1/signup' \ -H 'apikey: YOUR_ANON_KEY' \ -H 'Content-Type: application/json' \ -d '{ "phone": "+86xxxxxxxxx", "password": "password" }'After you receive the text message on your phone, use the verification code to confirm.
curl -X POST 'https://<SUPABASE_PUBLIC_URL>/auth/v1/verify' \ -H 'apikey: YOUR_ANON_KEY' \ -H 'Content-Type: application/json' \ -d '{ "phone": "86xxxxxxxxx", "type": "sms", "token": "xxxxxx" }'
Call using supabase-js
For information about how to install and use supabase-js, see supabase-js.
Call the sign-up API.
const { data, error } = await supabase.auth.signUp( { phone: '+86xxxxxxxxx', password: 'password', options: { data: { first_name: 'John', age: 27, } } } )After you receive the text message on your phone, use the verification code to confirm.
const { data, error } = await supabase.auth.verifyOtp({ phone, token, type: 'sms'})