Skip to main content

Anonymous Login

Under anonymous login status, users can normally access CloudBase resources. Developers can configure corresponding access restrictions for anonymous users in conjunction with security rules.

Precondition

Enabling Anonymous Login

  1. Go to CloudBase Console/Authentication/Login Methods
  2. In the login methods list, select Anonymous Login and click Enable.

Login Flow

For the auth instance, see SDK Initialization

Auth.signInAnonymously is used for anonymous login

await auth.signInAnonymously();
const loginScope = await auth.loginScope();
// If it is an anonymous login, returns true.
console.log(loginScope === "anonymous");

Converting to Formal Account

If users generate some private data in an anonymous state (such as personal achievements and equipment obtained in games), and want to convert this anonymous account into a formal account for long-term retention.

For this requirement, you can perform anonymous user conversion registration to transfer the private data of this anonymous account to a formal account.

Conversion Example Reference:

  1. Anonymous Login
const auth = app.auth();
await auth.signInAnonymously();
  1. Obtain the access_token and perform conversion registration.
const {
accessToken
} = await auth.getAccessToken();

await auth.signUp({
// For other parameters, see auth.signUp.
anonymous_token: accessToken,
});
Tip

Additionally, see Account Linking