66 lines
1.3 KiB
Markdown
66 lines
1.3 KiB
Markdown
---
|
|
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
|
|
|
|
```js
|
|
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:
|
|
|
|
```json
|
|
{
|
|
"id": "user-alice-01",
|
|
"username": "alice",
|
|
"displayName": "Alice",
|
|
"description": "Raids on Fridays",
|
|
"avatarUrl": "/avatars/alice.webp"
|
|
}
|
|
```
|
|
|
|
## Update Display Profile
|
|
|
|
```js
|
|
export function activate(context) {
|
|
context.api.profile.update({
|
|
displayName: 'Alice - Support Lead',
|
|
description: 'Available for onboarding and support questions.'
|
|
});
|
|
}
|
|
```
|
|
|
|
## Update Avatar
|
|
|
|
```js
|
|
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. |