
What am I doing wrong?
I have a function that get trigger for every users.*.create
and it does the following:
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:
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?

Is document level security enabled on the collection?

Dang! No it wasnt, works now! <:appwritecheers:892495536823861258>

[SOLVED] AppwriteException: user_unauthorized
Recommended threads
- Is Quick Start for function creation wor...
I am trying to create a Node.js function using the Quick Start feature. It fails and tells me that it could not locate the package.json file. Isn't Quick Start ...
- Connecting server functions to GitHub re...
The project I am working in has recently moved organizations on Appwrite. The same is true for the repo on GitHub, which as moved from a private user to a organ...
- Missing C++ libstdc library in Python fu...
I have a function running Python 3.12 which suddenly started dumping errors (as of today; it worked yesterday). I hadn't changed any code so I found this odd, b...
