SMS Verification Code Login
Using SMS verification code login, you can allow users to register and log in to CloudBase using their own phone number, combined with SMS verification code or password, and also update or unbind the phone number used for login.
Usage Limits and Fees
- Newly activated pay-as-you-go environments, or those activated before April 9, 2021, enjoy a free quota of 100 items in the first month;
- For demands exceeding the free quota, developers can go to the CloudBase console to purchase resource packages;
- SMS delivery is subject to frequency limits:
- A maximum of 1 message can be sent to the same phone number within 30 seconds;
- A maximum of 10 messages can be sent to the same phone number within a calendar day;
Enable SMS Verification Code Login
Go to the CloudBase console, and on the Login Authorization settings page, enable SMS verification code login:
Login Process
Step 1: Initializing the SDK
- Web
import cloudbase from "@cloudbase/js-sdk";
const app = cloudbase.init({
env: "your-env-id"
});
Step 2: Registering an Account Using Phone Number
First, the user needs to enter their phone number, then call the SDK's send SMS verification code interface:
- Web
app
.auth()
.sendPhoneCode(phoneNumber)
.then(() => {
// Send SMS verification code
});
After calling the SMS sending interface, the mobile phone will receive the CloudBase SMS verification code. The user then enters the SMS verification code and a custom password, and calls the account registration interface.
- Web
app
.auth()
.signUpWithPhoneCode(phoneNumber, phoneCode, password)
.then(() => {
// Register account via SMS
});
Password length should be not less than 8 and not greater than 32, and should contain both letters and numbers.
Step 3: Log in to CloudBase using phone number + password or phone number + SMS verification code
- Web
app
.auth()
.signInWithPhoneCodeOrPassword({
phoneNumber,
phoneCode, // Optional; at least one of verification code or password must be provided
password // Optional; at least one of verification code or password must be provided
})
.then((loginState) => {
// Login successful
});