Skip to main content

Email Login

By using email login, you can allow your users to register and log in to CloudBase using their own email and password, and also update the email and password used for login.

Version Information
  • Login Authentication (v2) applies to @cloudbase/js-sdk@2.x version
  • If you are using SDK version 1.x, please refer to Login Authentication (v1)
  • v2 version currently does not support Official Account login. If you need to use this method, please use the v1 version

This document will introduce using the V2 version.

Preparatory Actions

Enable Email Login

  1. Go to CloudBase/Authentication
  2. In the list of login methods, select Email Login - Configure Sender
  3. Configure the email sender SMTP settings and then enable email login

Common Email SMTP Configuration

EmailSMTP Server HostSMTP Server PortSMTP Security Mode
QQ Mailsmtp.qq.com465/587SSL(465)/STARTTLS(587)
Tencent Enterprise Emailsmtp.exmail.qq.com465SSL
163 Mailsmtp.163.com465SSL
gmailsmtp.gmail.com465/578SSL(465)/STARTSSL(587)

Registration Process

When registering with email, you need to first send an email verification code, then complete registration using the code.

auth instance, please refer to SDK Initialization

// 1. Send email verification code
const email = "test@example.com";
const verification = await auth.getVerification({
email: email
});

// 2. Verify the verification code
// Assume the user-entered verification code "000000" 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
});
// 3. If the user already exists, log in
if (verification.is_user) {
await auth.signIn({
username: email,
verification_token: verificationTokenRes.verification_token
});
} else {
// 4. Otherwise, register a new user. When registering a new user, you can set the password and username.
// Remark: Upon successful signUp, the user will be automatically logged in.
await auth.signUp({
email: email,
verification_code: verificationCode,
verification_token: verificationTokenRes.verification_token,
// Optional, set nickname.
name: "Mobile User",
// Optional, set password.
password: "password",
// Optional, set login username.
username: "username"
});
}
Password Strength Requirements

Password length should be not less than 8 and not greater than 32, and should contain both letters and numbers.

Login Flow

Email-Password Login

The Auth.signIn method can be used for phone number, email, username login

  await auth.signIn({
username: email,
password: "your-password"
});

Verification Code Login

The Auth.signInWithEmail method can be used for phone number verification code login

const email = 'xxx'

// Send the verification code
const verificationInfo = await auth.getVerification({
email: email,
});

// Assume the user-entered verification code "000000" is received here
const verificationCode = "000000";

// Verification Code Login
await auth.signInWithEmail({
verificationInfo,
verificationCode: verificationCode,
email: email,
});

Common Email Servers

QQ Mail

Step 1: Log in to QQ Mail

Go to the QQ Mail homepage and log in to your QQ Mail account.

Step 2: Enable IMAP/SMTP Service

After logging in to your email, go to "Settings - Account":

Then, in the "Account" settings, locate the "Enable Service" option and enable the IMAP/SMTP service:

After enabling successfully, please save your email login authorization code:

Note

You can also enable the POP3/SMTP service. The authorization codes for both services can be used as the SMTP account password in Step 3.

Step 3: Configure QQ Mail as the Sender

Use QQ Mail as the sender address and SMTP account username, and use the authorization code from Step 2 as the SMTP account password.

gmail Mail

Step 1: Log in to gmail

gamil Mail has IMAP/SMTP service enabled by default. This step verifies whether the email is usable.

Step 2: Enable google account two-step verification

https://myaccount.google.com/security?utm_source=OGB&utm_medium=app

Click on Security --> 2-Step Verification to enable it.

Step 3: Enable google account app password

https://support.google.com/accounts/answer/185833?hl=zh-Hans

Step 4: Configure the Cloud Development Platform email login SMTP

EmailSMTP Server Host
SenderYour gmail Mail
SMTP Server Hostsmtp.gmail.com
Port465
SMTP Account UsernameYour gmail Mail
SMTP Account Passwordthe app password from Step 3
SMTP Security ModeSSL