Rank 4: Virtual Machine
AppwriteException: user_unauthorized, The current user is not authorized to perform the requested action. (401) Getting this error continously```Votes
0
Replies
24
Participants
16
Messages
25
Rank 4: Virtual Machine
AppwriteException: user_unauthorized, The current user is not authorized to perform the requested action. (401) Getting this error continously```Rank 4: Virtual Machine
I maybe could test it in an hour or so
@Arif Qayoom i have some questions regarding this:
Are you using client SDK or server SDK or a mix of both both?
Do you have guest access enabled in your project auth
Do you have row (legacy document) level security turn on in that table (legacy collection)
Spot on. Didn't notice this reply earlier
^^
actually @nathfavour we are stupid with the first ig, it's tagged flutter
which answers the first question xD
Rank 4: Virtual Machine
I am using only client side, Flutter & using https://appwrite.io/docs/products/auth/presences & used this for documentation & its like chats App
Nice catch, nice catch😅
That narrows it down it down greatly to either RLS permission, or invalid session
could you run
try { const user = await account.get({}); log(user.toString());} catch (err) { log(err);}before it to verify that you have a valid session
replace "account" with your account variable that you have created
Rank 4: Virtual Machine
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 updo you have a valid session? what is the result of this snippet
Rank 4: Virtual Machine
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} ---
Rank 4: Virtual Machine
This is the result I am getting
Rank 4: Virtual Machine
@Turboman 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)
@Arif Qayoom are you using the same ID for the upsert?
Rank 4: Virtual Machine
ID unique .. & Tried to use UserId alsso but nothing changed
how does your Presence call look like? @Arif Qayoom
Rank 4: Virtual Machine
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'); } }```Rank 4: Virtual Machine
You are always creating a new id for the presence, i would recommend you to store presence id to make it persitent
Which is my last idea i have, if it still occurs then idk actually...