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
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...
- Function in Node.JS to monitor events ar...
Hello everyone. I'm creating my first Node.JS function, but I don't have much experience with node and javascript. I'm trying to create a function, that monito...