tencent cloud

Managing Login Methods
Last updated:2025-12-31 11:48:17
Managing Login Methods
Last updated: 2025-12-31 11:48:17

Creating Users

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

Obtaining the Currently Logged In User

You can use the auth.currentUser attribute or the auth.getCurrentUser method to get the currently logged in user. This method will return the user instance of the current logged in user. If the user is not logged in, it will return null:
const app = cloudbase.init({
env: "xxxx-yyy"
})
const auth = app.auth()
// After logging in...
const user = auth.currentUser
// Or
// const user = await auth.getCurrentUser()

Obtaining User Personal Information

You can obtain the user's personal information through various attributes of the user object:
const user = auth.currentUser
let uid, name, gender, created_from
if (user) {
// CloudBase unique user ID
uid = user.uid
// Nickname
name = user.name
// Gender
gender = user.gender
// Creation source
created_from = user.created_from;
}

Updating User Personal Information

You can use the User.update method to update the user's personal information. For example:
const user = auth.currentUser

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

Refreshing User 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;
});

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback