I cant update the document even I have the permission in server side using JWT token
- 1
- Databases
- Cloud
const jwtClient = new Client();
jwtClient
.setEndpoint(Bun.env.APPWRITE_FUNCTION_ENDPOINT)
.setProject(Bun.env.APPWRITE_FUNCTION_PROJECT_ID)
.setJWT(token);
const users = new Users(client);
const functions = new Functions(client);
const databases = new Databases(client);
const jwtDatabases = new Databases(jwtClient);
/// .....
const userDocument: UserDocument = await jwtDatabases.updateDocument(
Bun.env.DATABASE_ID,
Bun.env.USER_COLLECTION_ID,
id,
{
name,
phoneNumber,
...(email ? { email } : {}),
...(regionRef ? { regionRef } : {}),
...(provinceRef ? { provinceRef } : {}),
...(cityRef ? { cityRef } : {}),
...(barangayRef ? { barangayRef } : {}),
enabled,
role,
}
);
log("User cache document updated");
Remember that I have log before and after of
updateDocument
This is the error response from execution:
{"name":"AppwriteException","code":401,"type":"user_unauthorized","response":{"message":"Permissions must be one of: (any, users, user:65c86c61c9443bebd995, user:65c86c61c9443bebd995/verified, users/verified, label:superadmin)","code":401,"type":"user_unauthorized","version":"1.5.7"}}
And this is the logs:
Initializing Appwrite client
Setting API key for Appwrite client
Request received by /v1/users/666a6e20bd83c928b2e8 with method PUT
Triggered type: http
Event type: undefined
Matched route: /users/666a6e20bd83c928b2e8 with method PUT
userUpdateHandler triggered with 666a6e20bd83c928b2e8 and role techAssistant
Getting user details
Checking if the user is authorized to update a user
Updating user cache document
User cache document updated
Updating user details
Updating role
Role updated
Regenerating permissions
Permissions regenerated
As you can see it run through my codes of my function. Remember that I have log Updating user cache document -> call updateDocument -> User cache document updated. So it supposed to be not error right?. When I see my database it actually successfully updated the document but it give me an error that the user have not permission to update the document. The user actually have the permission to update that document because he is the superadmin
Recommended threads
- Project paused?
Hello, I have two Appwrite projects and I can not resume them for some reason. I'm using the free plan, and I saw in the pricing page that 2 free projects are a...
- Help
- Python TablesDB Rework
Hi, i starting to rework some older functions to TablesDB list_rows Method. I used list_documents with a resultset with worked fine. Now i tried to get all rows...