SMS Verification Code Login
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
- Go to CloudBase Console/Authentication/Login Methods
- In the login methods list, find "SMS Verification Code Login" and enable it
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 numbers must include country code, for example, mainland China phone number format is +86 13800000000
Usage Limits and Costs
Free Quota
- CloudBase prepaid environments enjoy a free quota of 100 messages in the first month
- After exceeding the free quota, developers can purchase SMS resource packages at CloudBase Console/Resource Packages
Frequency Limits
SMS delivery has the following frequency limits:
| Limit Type | Limit Rule | Description |
|---|---|---|
| Single Number Send Frequency | Maximum 1 message per 30 seconds | Prevent malicious SMS abuse |
| Single Number Daily Send Limit | Default maximum 30 messages/day | Upper limit can be modified in console |
You can modify these settings in CloudBase Console/Authentication/Login Methods by selecting "SMS Verification Code".
Custom SMS Template
When using the default CloudBase SMS resource package, SMS template content cannot be modified. If you have the following requirements:
- Customize SMS verification code template content
- Customize SMS signature
- Use other SMS service providers
You can integrate an external SMS channel.
Integration Steps
Step 1: Configure SMS template and signature on external SMS service platform
Configure templates and signatures on the external SMS service platform.
Step 2: Integrate with CloudBase Console
Configure the integration in CloudBase Console/Extensions/Create APIs.
For example, to integrate with Tencent Cloud SMS service, refer to this guide: Tencent Cloud SMS
Step 3: Enable custom channel
After configuration is complete, go to CloudBase Console/Authentication/Login Methods → SMS Verification Code, select and check "Custom SMS Channel" to use the custom SMS template.