1.3 KiB
1.3 KiB
sidebar_position
| sidebar_position |
|---|
| 2 |
Profile API
The profile API reads and updates the current user's local profile details.
Required Capabilities
| Method | Capability |
|---|---|
profile.getCurrent() |
profile.read |
profile.update(profile) |
profile.write |
profile.updateAvatar(avatar) |
profile.write |
Read Current Profile
export function activate(context) {
const user = context.api.profile.getCurrent();
context.api.logger.info('Current profile', {
id: user?.id,
displayName: user?.displayName,
username: user?.username
});
}
Example result:
{
"id": "user-alice-01",
"username": "alice",
"displayName": "Alice",
"description": "Raids on Fridays",
"avatarUrl": "/avatars/alice.webp"
}
Update Display Profile
export function activate(context) {
context.api.profile.update({
displayName: 'Alice - Support Lead',
description: 'Available for onboarding and support questions.'
});
}
Update Avatar
export function activate(context) {
context.api.profile.updateAvatar({
avatarUrl: 'https://cdn.example.com/metoyou/avatars/alice-support.png',
avatarMime: 'image/png',
avatarHash: 'sha256:9df5d5e4b0d8f41f3a3cf5d1f5a2c1f4'
});
}
Use profile.write carefully. A plugin that changes a user's identity should explain why in its readme and UI.