Skip to main content

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

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,
});

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
  1. Can contain numbers and letters, but cannot be all numbers.
  2. Only the symbols - and _ are allowed, and they cannot appear at the beginning or end.
  3. The length range is [1, 32]. :::

After successful registration, you can view and manage user information in TCB Platform/Authentication/User Management.