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
- Type Mismatch in AppwriteException
There is a discrepancy in the TypeScript type definitions for AppwriteException. The response property is defined as a string in the type definitions, but in pr...
- [SOLVED] OAuth With Google & Flutter
Hi all, I'm trying to sign in with google and it all goes swimmingly until the call back. I get a new user created on the appwrite dashboard however the flutte...
- What Query's are valid for GetDocument?
Documentation shows that Queries are valid here, but doesn't explain which queries are valid. At first I presumed this to be a bug, but before creating a githu...