Skip to main content

Manage Users

Create User

Developers can call the following login methods to sign in or create a user:

User Types

Users are categorized into internal users, external registered users, and anonymous users:

User TypeRoleUser LimitUser Information
Internal usersFixed "Default Internal User Role", with option to assign custom rolesSubject to plan limitations. Refer to Billing DocumentationStored by the system
External registered usersFixed "Default External User Role"UnlimitedStored by the system
Anonymous usersFixed "Default Visitor Role"UnlimitedNot stored by the system

Get Currently Logged-in User

auth instance please refer to SDK Initialization

You can use the auth.currentUser property or the auth.getCurrentUser() method to get the currently logged-in user, which returns a User instance. If the user is not logged in, it returns null:

const app = cloudbase.init({
env: "xxxx-yyy"
})
const auth = app.auth()

// After logging in...

// Get user information
const user = auth.currentUser
// Or
// const user = await auth.getCurrentUser()

Get User Profile

You can obtain the user's profile information through various properties of the User object:

const user = auth.currentUser
let uid, name, gender, created_from

if (user) {
// Cloud Base unique user ID
uid = user.uid

// Nickname
name = user.name

// Gender
gender = user.gender

// Creation source
created_from = user.created_from;
}

Update User Profile

You can use the User.update method to update the user's profile information. For example:

const user = auth.currentUser

user
.update({
name: "Tony Stark",
gender: "MALE"
})
.then(() => {
// User information is updated successfully.
});

Refresh User Profile Information

For a multi-device application, users may update their personal information on one device, and other devices may need to refresh the information:

const user = auth.currentUser;

// Refresh user information.
user.refresh().then(() => {
// After refreshing, the obtained user information will be the latest.
const {
username,
gender
} = user;
});