Skip to content
Back

Issue Related to Presence

  • 0
  • 16
  • Flutter
  • Cloud
7 Jul, 2026, 04:36
TypeScript
AppwriteException: user_unauthorized, The 
current user is not authorized to perform 
the requested action. (401)            Getting this error continously```
TL;DR
The user is facing an issue related to the presence documentation in dart sdk. The provided code snippet contains examples for setting up a server client, creating or updating a presence log, patching specific fields, fetching a presence by ID, and listing presences.
7 Jul, 2026, 13:16

<@&1201605261148815501> <@&634618551491100692>

7 Jul, 2026, 13:29

I maybe could test it in an hour or so

7 Jul, 2026, 13:34

<@999025209908666441> i have some questions regarding this:

  • How are you calling it? Rest, CLI or SDK (and if yes which SDK)
  • Did you verifify that you have an active session
1
7 Jul, 2026, 13:34
  1. Are you using client SDK or server SDK or a mix of both both?
  2. Do you have guest access enabled in your project auth
  3. Do you have row (legacy document) level security turn on in that table (legacy collection)
7 Jul, 2026, 13:35

Spot on. Didn't notice this reply earlier

7 Jul, 2026, 13:36

^^

7 Jul, 2026, 13:36

actually <@1073182954672627752> we are stupid with the first ig, it's tagged flutter

1
7 Jul, 2026, 13:37

which answers the first question xD

7 Jul, 2026, 13:38

I am using only client side, Flutter & using https://appwrite.io/docs/products/auth/presences & used this for documentation & its like chats App

7 Jul, 2026, 13:40

Nice catch, nice catch๐Ÿ˜…

That narrows it down it down greatly to either RLS permission, or invalid session

7 Jul, 2026, 13:40

could you run

TypeScript
try {
  const user = await account.get({});
  log(user.toString());
} catch (err) {
  log(err);
}

before it to verify that you have a valid session

7 Jul, 2026, 13:41

replace "account" with your account variable that you have created

1
7 Jul, 2026, 13:53
TypeScript
Error setting up presence: AppwriteException: user_unauthorized, The current user is not authorized to perform the requested action. (401)```   For the first time It is working but when I closes app & Started app then this error is showing up
7 Jul, 2026, 13:54

do you have a valid session? what is the result of this snippet

7 Jul, 2026, 14:05

I/flutter (27182): --- Account GET successful: {$id: 6a4b59ca430880c00c73, $createdAt: 2026-07-06T07:31:22.258+00:00, $updatedAt: 2026-07-07T12:52:48.191+00:00, name: arifqayoom39, password: null, hash: null, hashOptions: null, registration: 2026-07-06T07:31:22.257+00:00, status: true, labels: [], passwordUpdate: 2026-07-06T07:31:22.257+00:00, email: a*****39@gmail.com, phone: , emailVerification: false, emailCanonical: a*****39@gmail.com, emailIsFree: true, emailIsDisposable: false, emailIsCorporate: false, emailIsCanonical: true, phoneVerification: false, mfa: false, prefs: {data: {}}, targets: [{$id: 6a4b59ca4cad247aacea, $createdAt: 2026-07-06T07:31:22.314+00:00, $updatedAt: 2026-07-06T07:31:22.314+00:00, name: , userId: 6a4b59ca430880c00c73, providerId: null, providerType: email, identifier: a*****39@gmail.com, expired: false}], accessedAt: 2026-07-07T12:52:48.187+00:00, impersonator: false, impersonatorUserId: null} ---

7 Jul, 2026, 14:05

This is the result I am getting

7 Jul, 2026, 14:07

<@262572967358234634> For the first time it works well & show Online status to other user but when I closed this app & then restarted it shows I/flutter (27182): Error setting up presence: AppwriteException: user_unauthorized, The current user is not authorized to perform the requested action. (401)

7 Jul, 2026, 15:03

<@999025209908666441> are you using the same ID for the upsert?

7 Jul, 2026, 15:09

ID unique .. & Tried to use UserId alsso but nothing changed

7 Jul, 2026, 15:57

how does your Presence call look like? <@999025209908666441>

7 Jul, 2026, 17:24
TypeScript
    final client = AppwriteConfig.client;
    final presences = Presences(client);

    try {
      // 1. Mark self as online in this room
      final p = await presences.upsert(
        presenceId: ID.unique(),
        status: 'online',
        metadata: {'roomId': widget.room.id},
        permissions: [
          Permission.read(Role.users()), // Allow others to see our presence
        ],
      );
      _presenceId = p.$id;

      // 2. Initial fetch to see if the other user is already online
      final activeList = await presences.list(
        queries: [Query.equal('userId', widget.user.id)],
      );
      bool found = false;
      for (var presence in activeList.presences) {
        if (presence.status == 'online' &&
            presence.metadata?['roomId'] == widget.room.id) {
          found = true;
          break;
        }
      }
      if (mounted) {
        setState(() => _isOtherUserOnline = found);
      }

      // 3. Subscribe to presences
      final realtime = AppwriteConfig.realtime;
      _presenceSubscription = realtime.subscribe(['presences']);
      _presenceSubscription.stream.listen((response) {
        final payload = response.payload;
        if (payload['userId'] == widget.user.id) {
          final isDelete = response.events.any((e) => e.contains('.delete'));
          final isOnline = payload['status'] == 'online';
          final inRoom = payload['metadata']?['roomId'] == widget.room.id;

          if (mounted) {
            setState(() {
              if (isDelete) {
                _isOtherUserOnline = false;
              } else {
                _isOtherUserOnline = isOnline && inRoom;
              }
            });
          }
        }
      });
    } catch (e) {
      print('Error setting up presence: $e');
    }
  }```
7 Jul, 2026, 17:28

<@262572967358234634>

7 Jul, 2026, 17:49

You are always creating a new id for the presence, i would recommend you to store presence id to make it persitent

7 Jul, 2026, 17:49

Which is my last idea i have, if it still occurs then idk actually...

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more