Repository navigation
Description
👟 Reproduction steps
- Self-hosted Appwrite 2.4.0, a signed-in user (client session).
- Create a presence exactly as in the docs (
/docs/apis/realtime/presences):→ 200, the record hasawait presences.upsert({ presenceId, status: 'online', permissions: [Permission.read(Role.users())] });
$permissions: ["read(\"users\")"]only. - Follow the documented heartbeat pattern and upsert again with the same arguments → 401
user_unauthorized. presences.update({ presenceId, status: 'away' })→ 401.presences.delete({ presenceId })(documented for sign out) → 401.- Same over Realtime:
realtime.upsertPresence({ status: 'online', permissions: [Permission.read(Role.users())] })works once; the nextupsertPresenceon the same or another connection of the same user returns anerrorwith code 401.
Without permissions, or with update("user:<id>")/delete("user:<id>") added, every step succeeds.
👍 Expected behavior
As documented: "Client sessions can always update their own presence without an extra scope." The owner can heartbeat, change status and delete their presence regardless of which read roles were granted.
👎 Actual Behavior
Passing permissions replaces the default owner permissions entirely, so a presence created with only read roles is read-only for its own owner. Heartbeat, status change and sign-out cleanup all fail with 401. Over REST the stale presence then lingers until expiresAt; over Realtime until the connection closes. Reproduced 2 of 2 runs, REST and Realtime.
Cause: Presences\State::setPermissions() uses the given permissions as-is and only adds owner permissions when permissions is null; upsertForUser() then updates the existing row through upsertDocument()/updateDocument(), which requires update permission. The same code is in every release since 2.0.0.
📄 Related docs problem
The "Scoping who can see a presence" section shows a client-web example that shares a typing indicator only with the DM recipient: permissions: [Permission.read(Role.user('<RECIPIENT_USER_ID>'))]. From a client session this always fails with 401 Permissions must be one of: (…) (REST and Realtime, reproduced 2/2), because a client may only grant roles it holds itself (Presences\State::checkPermissions()). The same applies to Role.team() for teams the user is not in and to labels. The example only works from a server SDK, which the docs do not say.
🎲 Appwrite version
2.4.0; the same code exists since presences were introduced in 2.0.0
💻 Operating system
Linux (Debian 12), Docker
🧱 Your Environment
Self-hosted, Postgres adapter, two API/realtime nodes.
💡 Suggested fix
Either always grant the owning user update/delete on their own presence (as the docs promise), or authorize presence writes by userId ownership instead of document permissions. Alternatively fix the docs and every SDK example to include Permission.update(Role.user(userId)) and Permission.delete(Role.user(userId)).
👀 Have you spent some time to check if this issue has been raised before?
- I checked and didn't find a similar issue
🏢 Have you read the Code of Conduct?
- I have read the Code of Conduct
Activity
nk0273926 commentedon Oct 12, 2026
I'd like to work on this issue. The root cause appears to be that explicitly passing
permissionsreplaces the default owner permissions, leaving the presence owner unable to update or delete their own presence.I propose ensuring that the owning user retains the necessary
updateanddeletepermissions, even when custom read permissions are supplied, in accordance with the documented behavior. I'll also investigate the client-side permission validation issue and update or add regression tests covering REST and Realtime presence upserts, updates, and deletion with custom permissions.