Manage User Profile

To check or update details of the current user profile:

1
2
3
4
5
6
val currentUser = GetSocial.getCurrentUser()
if (currentUser == null) {
    // SDK is not initialized yet
    return
}
// use currentUser object
1
2
3
4
5
guard let currentUser = GetSocial.currentUser() else {
    // SDK is not initialized yet
    return
}
// use currentUser object
1
2
3
4
5
6
7
var currentUser = GetSocial.GetCurrentUser();
if (currentUser == null)
{
    // SDK is not initialized yet
    return;
}
// use currentUser object
1
2
3
4
5
6
var currentUser = await GetSocial.currentUser;
if (currentUser == null) {
    // SDK is not initialized yet
    return;
}
// use currentUser object

Getters

1
2
3
4
5
6
// couple of examples
val displayName = currentUser.displayName
val avatarUrl = currentUser.avatarUrl
val publicProperties = currentUser.publicProperties
val privatProperties = currentUser.privateProperties
val identities = currentUser.identities
1
2
3
4
5
6
// couple of examples
let displayName = currentUser.displayName
let avatarUrl = currentUser.avatarUrl
let publicProperties = currentUser.publicProperties
let privatProperties = currentUser.privateProperties
let identities = currentUser.identities
1
2
3
4
5
6
// couple of examples
var displayName = currentUser.DisplayName;
var avatarUrl = currentUser.AvatarUrl;
var publicProperties = currentUser.PublicProperties;
var privateProperties = currentUser.PrivateProperties;
var identities = currentUser.Identities;
1
2
3
4
5
6
// couple of examples
var displayName = currentUser.displayName;
var avatarUrl = currentUser.avatarUrl;
var publicProperties = currentUser.publicProperties;
var privateProperties = currentUser.privateProperties;
var identities = currentUser.identities;

Properties Update

To update the user profile use UserUpdate class. It allows you update few user properties(custom and not) in one request:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
val batchUpdate = UserUpdate()
    .updateAvatarUrl(newAvatarUrl)
    .updateDisplayName(newDisplayName)
    .setPublicProperty(publicProperty1, newPublicValue)
    .removePublicProperty(publicProperty2)
    .setPrivateProperty(privateProperty1, newPrivateValue)
    .removePrivateProperty(privateProperty2)

curentUser.updateDetails(batchUpdate, {
    Log.d("CurrentUser", "User details were successfully updated")
}, { error ->
    Log.d("CurrentUser", "Failed to update user details, error: ${error}")
})
1
2
3
4
5
6
7
8
9
var batchUpdate = UserUpdate()
batchUpdate.avatarUrl = newAvatarUrl
batchUpdate.displayName = newDisplayName
batchUpdate.setPublicProperty(value: newPublicValue, key: publicProperty1)
batchUpdate.removePublicProperty(publicProperty2)
batchUpdate.setPrivateProperty(value: privateProperty1, forKey: newPrivateValue)
batchUpdate.removePrivateProperty(privateProperty2)

currentUser.updateDetails(batchUpdate, success: success, failure: failure)
1
2
3
4
5
6
7
8
var batchUpdate = new UserUpdate();
batchUpdate.AvatarUrl = newAvatarUrl
batchUpdate.DisplayName = newDisplayName
batchUpdate.AddPublicProperty(publicProperty1, newPublicValue);
batchUpdate.RemovePublicProperty(publicProperty2);
batchUpdate.AddPrivateProperty(newPrivateValue, privateProperty1);
batchUpdate.RemovePrivateProperty(privateProperty2);
currentUser.UpdateDetails(batchUpdate, OnSuccess, OnFailure);
1
2
3
4
5
6
7
8
9
var batchUpdate = UserUpdate();
batchUpdate.updateAvatarUrl(newAvatarUrl);
batchUpdate.updateDisplayName(newDisplayName);
batchUpdate.setPublicProperty(publicProperty1, newPublicValue);
batchUpdate.removePublicProperty(publicProperty2);
batchUpdate.setPrivateProperty(newPrivateValue, privateProperty1);
batchUpdate.removePrivateProperty(privateProperty2);
var currentUser = await GetSocial.currentUser;
currentUser.updateDetails(batchUpdate);

Reference

You can read about CurrentUser methods in the reference for Android and iOS.

Next Steps

Well-done! Your user is set up, see what to do next:

Give us your feedback! Was this article helpful?

😀 🙁