User Management
User Types
CloudBase provides three user types, each suitable for different business scenarios:
| User Type | Role | User Limit | User Information | Creation Method | Login Method |
|---|---|---|---|---|---|
| Organization Member | Users 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 User | Users registered through any registration method Fixed "Registered User" role Corresponds to "External Users" in legacy user system | Unlimited users | System saved | - Users self-register through User Registration - Admin manually adds at CloudBase Platform/Authentication/User Management page | Login Methods |
| Anonymous User | Fixed "Default Visitor" role | Unlimited users | Not saved by system | No registration required | Anonymous 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
authinstance 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
| Property | Type | Description |
|---|---|---|
uid | string | CloudBase unique user ID |
name | string | User nickname |
gender | string | User gender (MALE/FEMALE/UNKNOWN) |
created_from | string | User creation source |
💡 Tip: For more user properties, refer to
Userobject 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
| Field | Type | Description |
|---|---|---|
name | string | User nickname |
gender | string | User 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
- Store Extra User Information - How to use custom user tables to store business-related extension information
- Grant Admin Permission to Registered Users - How to convert registered users to organization members and assign admin roles
Related Documentation
- Permission Control - Role system and permission configuration
- User Registration - User registration
- Best Practices - Best practices for authentication and permission management