IpsokaOriginal post
Rank 2: Process
What am I doing wrong?
I have a function that get trigger for every users.*.create and it does the following:
Dart
Map<String, dynamic> functionData = jsonDecode(req.variables['APPWRITE_FUNCTION_EVENT_DATA']); String userId = functionData["\$id"]; await database.createDocument( databaseId: "---database id ---", collectionId: "--- collection id ---", documentId: userId, permissions: [Permission.read(Role.user(userId))], data: { "code": "--- random code ---" }, );The document gets created successfully but client side
Client side i'm doing the following:
Dart
User user = await account.get(); Document document = await databases.getDocument( databaseId: "---database id ---", collectionId: "--- collection id ---", documentId: user.$id, );Which throws:
AppwriteException: user_unauthorized, The current user is not authorized to perform the requested action. (401)
I am logged in as the user the triggered the function, so it should work or no?
Summary
The user is encountering an "AppwriteException: user_unauthorized" error when trying to access a document. They are using document level security in their function code and are logged in as the user who triggered the function. They are unsure why they are getting the authorization error.
Solution: Check if document level security is enabled on the collection. If it is enabled, ensure that the user has the necessary permissions to read the document.
