Skip to main content

SMS Verification Code Login

Note

SMS verification code login is only supported in the Shanghai region

With SMS verification code login, users can quickly log in using "phone number + SMS verification code" without needing to remember a password.

Prerequisites​

Enable SMS Verification Code Login​

  1. Go to CloudBase Console/Authentication/Login Methods
  2. In the login methods list, find "SMS Verification Code Login" and enable it

Verification Code Configuration Guide​

To use SMS verification code login, you need to integrate an SMS service provider (such as Tencent Cloud SMS) to send verification code messages.

Configuration Steps​

  1. Go to the Tencent Cloud SMS Console and apply for an SMS signature and SMS template, then wait for approval
  2. Go to CloudBase Console/Authentication/Login Methods, and fill in the applied signature and template information under "SMS Verification Code Login" to complete the configuration; alternatively, call the ModifyLoginConfig API to complete the configuration
  3. After configuration is complete, the verification code messages triggered during user registration/login will be sent through your configured SMS service provider

For detailed steps on applying for signatures and templates and API parameter descriptions, please refer to Custom SMS Provider Configuration Guide.

User Registration​

For user registration process, please refer to User Registration.

Login Process​

The Auth.signInWithSms method is used for SMS verification code login.

import cloudbase from "@cloudbase/js-sdk";

const app = cloudbase.init({
env: "your-env-id",
region: "ap-shanghai", // Defaults to Shanghai region if not provided
});

const auth = app.auth();

const phoneNumber = "+86 13800000000"; // Country code required

// Step 1: User clicks to get verification code, send SMS verification code
// Store verificationInfo in a global variable for use in step 3
const verificationInfo = await auth.getVerification({
phone_number: phoneNumber,
});

// Step 2: Wait for user to enter the received SMS verification code on the page
const verificationCode = userInputCode; // 6-digit verification code entered by user

// Step 3: Verify SMS code and log in
await auth.signInWithSms({
verificationInfo,
verificationCode, // SMS verification code entered by user
phoneNum: phoneNumber, // User's phone number
});
Phone Number Format

Phone numbers must include country code, for example, mainland China phone number format is +86 13800000000