User Registration
Currently supports registration via mobile phone verification code and email verification code.
The development of the two registration methods differs only during sending verification codes, while all subsequent verification steps are identical.
💡 Note: All registered users are external users. For internal user registration, see Internal User API.
Sending Verification Codes
- Mobile Phone Verification Code
- Email Verification Code
import cloudbase from "@cloudbase/js-sdk";
const app = cloudbase.init({
env: "your-env-id"
});
// Obtain the auth instance
const auth = app.auth();
// Send the mobile phone verification code
const phoneNumber = "+86 13800000000"; // The country/region code must be included
const verification = await auth.getVerification({
phone_number: phoneNumber,
});
import cloudbase from "@cloudbase/js-sdk";
const app = cloudbase.init({
env: "your-env-id"
});
// Obtain the auth instance
const auth = app.auth();
// Send the email verification code
const email = "test@example.com";
const verification = await auth.getVerification({
email: email,
});
Verify and Register
After obtaining the verification code, the next steps
// 1. Verify the verification code
// Assume the verification code "000000" entered by the user is received here.
const verificationCode = "000000";
// Verify the correctness of the Captcha.
const verificationTokenRes = await auth.verify({
verification_id: verification.verification_id,
verification_code: verificationCode,
});
// 2. Register
// If the user already exists, log in.
if (verification.is_user) {
await auth.signIn({
username: phoneNumber,
verification_token: verificationTokenRes.verification_token,
});
}
// Otherwise, register a new user and set a password and username.
else {
// Remark: Upon successful signUp, the user will be automatically logged in.
await auth.signUp({
phone_number: phoneNumber,
verification_code: verificationCode,
verification_token: verificationTokenRes.verification_token,
// Optional, set nickname.
name: name: "Mobile User",
// Optional, set password.
password: "password",
// Optional, set login username.
username: "username",
});
}
Username Rules
- May contain letters and digits, but cannot consist entirely of digits.
- Only the symbols
-and_are allowed, and they cannot appear at the beginning or the end. - Length range is within
[1, 32]
After successful registration, you can view and manage user information in CloudBase/Authentication/User Management.
