Update current user profile
Modify the nickname, avatar URL, or custom metadata string for the currently signed-in user.
Submit only the fields you wish to modify. The userID must match the signed-in account. Do not mix profile fields like nickname and avatar with global notification settings in a single operation:
Code example
import sdk, { EventOnSelfInfoUpdatedData, OpenIMSDKEvent, SetSelfInfoReq } from '@openimsdk/imsdk';
const request: SetSelfInfoReq = {
userID: currentUserID,
nickname: nickname.trim(),
faceURL: avatarURL,
ex: mergedExtra,
};
await sdk.setSelfInfo(request);
const handleSelfInfoUpdated = (data: EventOnSelfInfoUpdatedData): void => {
setCurrentUser(data.user);
};
const unsubscribeSelfInfo = sdk.on(OpenIMSDKEvent.EventOnSelfInfoUpdated, handleSelfInfoUpdated);
export function removeSelfInfoListener(): void {
unsubscribeSelfInfo();
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userID | string | Yes | Signed-in user identifier. |
nickname | string | No | New user nickname. |
faceURL | string | No | New avatar URL. |
ex | string | No | Updated complete custom metadata string. |
Return value
Returns a Promise that resolves to void upon updating the profile on the server.
State changes after the call
The ex field is an opaque string; the SDK does not automatically merge nested JSON schemas. If multiple features share this field, merge namespaced keys in application memory before saving. Promise resolution indicates that the server accepted the changes. Listen for EventOnSelfInfoUpdated to update reactive UI state across devices. Remove the listener via removeSelfInfoListener() upon sign-out. For manual reconciliation, re-query Retrieve current user profile. For notification and permission settings, see Set global message reception and Set friend request permission.
Was this page helpful?