User Registration
Currently supports phone number verification code, email verification code registration
The two registration methods differ only during send verification code in development, and the subsequent verification steps are identical.
💡 Note: Registered users are all external users. For internal user registration, see Internal User API
Send verification code
- Mobile Phone Verification Code
- Email Verification Code
Tip:
"Phone number verification code only supports the Shanghai region."
import cloudbase from "@cloudbase/js-sdk";
const app = cloudbase.init({
env: "your-env-id",
});
// Obtain the auth instance
const auth = app.auth();
// Send phone number verification code
const phoneNumber = "+86 13800000000"; // Country code required
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 email verification code
const email = "test@example.com";
const verification = await auth.getVerification({
email: email,
});
Verify and Register
Next steps after obtaining the verification code
// 1. Verify the verification code
// Assume we receive the user-entered verification code "000000"
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
- Can contain numbers and letters, but cannot be all numbers.
- Only the symbols
-and_are allowed, and they cannot appear at the beginning or end. - The length range is
[1, 32]. :::
After successful registration, you can view and manage user information in TCB Platform/Authentication/User Management.
