Skip to main content

User Management

User Types

CloudBase provides three user types, each suitable for different business scenarios:

User TypeRoleUser LimitUser InformationCreation MethodLogin Method
Organization MemberUsers within organizational structure
Support custom role assignment
Corresponds to "Internal Users" in legacy user system
Limited by plan
Refer to Billing Documentation
System saved- Add at CloudBase Platform/Authentication/Organization page
- Add via HTTP API
Login Methods
Registered UserUsers registered through any registration method
Fixed "Registered User" role
Corresponds to "External Users" in legacy user system
Unlimited usersSystem saved- Users self-register through User Registration
- Admin manually adds at CloudBase Platform/Authentication/User Management page
Login Methods
Anonymous UserFixed "Default Visitor" roleUnlimited usersNot saved by systemNo registration requiredAnonymous Login

User Type Description

Organization Users: Suitable for internal organization members, such as enterprise employees, team members, etc. Organization users can be assigned custom roles with more granular permission control. Users created at CloudBase Platform/Authentication/Organization page are organization users.

Registered Users: Suitable for end users of applications, such as C-side customers, community members, etc. Registered users have a fixed default registered user role with no user limit. Users manually created at CloudBase Platform/Authentication/User Management page are registered users.

Anonymous Users: Suitable for temporary access scenarios that don't require identity verification. The system doesn't save user information, and user identity cannot be traced after logout.

User Information Management

Get Current Logged-in User

You can get the current logged-in user's information through the auth.currentUser property or the auth.getCurrentUser() method.

Usage

import cloudbase from '@cloudbase/js-sdk';

const app = cloudbase.init({
env: 'your-env-id',
});

// Get auth instance
const auth = app.auth();

// After user login, get current user information
const user = auth.currentUser;
// Or use async method
// const user = await auth.getCurrentUser()

if (user) {
console.log('Current user UID:', user.uid);
} else {
console.log('User not logged in');
}

Return Value

This method returns the User instance of the current logged-in user. Returns null if the user is not logged in.

💡 Tip: For auth instance initialization, refer to SDK Initialization

Get User Profile

You can get user profile information through properties of the User object:

const user = auth.currentUser;

if (user) {
// CloudBase unique user ID
const uid = user.uid;

// User nickname
const name = user.name;

// User gender
const gender = user.gender;

// User creation source
const created_from = user.created_from;

console.log(`User ${name} (${uid}) has gender ${gender}`);
}

Common User Properties

PropertyTypeDescription
uidstringCloudBase unique user ID
namestringUser nickname
genderstringUser gender (MALE/FEMALE/UNKNOWN)
created_fromstringUser creation source

💡 Tip: For more user properties, refer to User object API documentation

Update User Profile

Use the User.update() method to update user profile information.

Usage Example

const user = auth.currentUser;

user.update({
name: 'Tony Stark',
gender: 'MALE',
})
.then(() => {
console.log('User profile updated successfully');
})
.catch((error) => {
console.error('Update failed:', error);
});

Updatable Fields

FieldTypeDescription
namestringUser nickname
genderstringUser gender (MALE/FEMALE/UNKNOWN)

⚠️ Note: Some user information (such as uid, created_from, etc.) are system fields and cannot be modified through this method

Refresh User Profile

In multi-platform applications, users may update their profile on one platform, and other platforms need to sync the latest information. Use the User.refresh() method to retrieve the latest user information from the server.

Usage Example

const user = auth.currentUser;

// Refresh user information
user.refresh()
.then(() => {
// Refresh successful, get latest user information
const { name, gender } = user;
console.log(`Current user: ${name}, gender: ${gender}`);
})
.catch((error) => {
console.error('Failed to refresh user information:', error);
});

Use Cases

  • User updated profile on another device or platform
  • Admin modified user information in backend
  • Need to get latest user status and permission information

💡 Tip: Refresh operation syncs latest data from server. It's recommended to call only when necessary to avoid frequent requests

Other References