Account Association
Each Cloud Base user account can be associated with other login methods in addition to the initial login method. After association, users can log in to the same Cloud Base account using any associated login method.
Mobile Number and Password Login Association
When the current user supports password login, you can associate a mobile number for the user. After association, the user can log in using "Mobile Number + Password":
- The user logs in using any login method.
- Obtain the
sudo_token. Here, thesudo_tokenis obtained via the password method. Alternatively, you can use methods such as email verification codes or mobile verification codes. For details, refer to theAuth.sudointerface.
import cloudbase from "@cloudbase/js-sdk";
const app = cloudbase.init({
env: "your-env-id"
});
// Obtain the auth instance
const auth = app.auth();
// Assume the user input password is passwd.
const password = "passwd";
// Obtain sudo_token. The expiration time of sudo_token defaults to 10 minutes.
const sudo_token = await auth.sudo({
password: password
});
- Send the verification SMS to the user's mobile phone.
// Assume the user's mobile phone number is 13800000000.
const phoneNumber = "+86 13800000000";
// Send the verification code
const verification = await auth.getVerification({
phone_number: phoneNumber
});
- Verify the user-entered verification code.
// Assume the user enters the Captcha 000000.
const verificationCode = "000000";
// Verify the Captcha.
const verificationTokenRes = await auth.verify({
verification_id: verification.verification_id,
verification_code: verificationCode
});
const verification_token = verificationTokenRes.verification_token;
- Bind the mobile phone number using
verification_tokenandsudo_token.
await auth.bindPhoneNumber({
sudo_token: sudo_token,
phone_number: phoneNumber,
verification_token: verification_token
});
Associate Email Password Login
If the current user supports password login, you can associate an email address for the user. After association, the user can log in using "Email + Password":
- The user logs in to CloudBase using any login method.
- Obtain the
sudo_token. Here, thesudo_tokenis obtained via the password method. Alternatively, you can use methods such as email verification codes or mobile verification codes. For details, refer to theAuth.sudointerface.
// Assume the user input password is passwd.
const password = "passwd";
// Obtain sudo_token. The expiration time of sudo_token defaults to 10 minutes.
const sudo_token = await auth.sudo({
password: password
});
- Send the verification code to the email address.
// Assume the user email is test@example.com.
const email = "test@example.com";
// Obtain email Captcha.
const verification = await auth.getVerification({
email: email
});
- Verify the user-entered verification code.
// Assume the user enters the Captcha 000000.
const verificationCode = "000000";
// Verify the Captcha.
const verificationTokenRes = await auth.verify({
verification_id: verification.verification_id,
verification_code: verificationCode
});
const verification_token = verificationTokenRes.verification_token;
- Use
verification_tokenandsudo_tokento bind the email address.
await auth.bindEmail({
sudo_token: sudo_token,
email: email,
verification_token: verification_token
});
Associate WeChat Login
Associate WeChat Login by following these steps:
The user logs in to CloudBase using any login method except WeChat login.
Refer to WeChat Authorized Login to obtain the WeChat authorization
provider_tokenUse the authorization
tokento associate WeChat login.
const app = cloudbase.init({
env: "xxxx-yyy"
});
const provider_token = "test_provider_token"; // the authorization token obtained in the previous step
const auth = app.auth();
await auth.bindWithProvider({
provider_token
});