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 Type | Role | User Limit | User Information |
---|---|---|---|
Internal users | Fixed "Default Internal User Role", with option to assign custom roles | Subject to plan limitations. Refer to Billing Documentation | Stored by the system |
External registered users | Fixed "Default External User Role" | Unlimited | Stored by the system |
Anonymous users | Fixed "Default Visitor Role" | Unlimited | Not 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;
});