Mosh OntongOriginal post
Quality
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
Summary
Developers are encountering a 401 error when attempting to update a document in their server-side application using a JWT token. Although the document is successfully updated in the database, the error suggests a lack of permission. The user, a superadmin, should have the necessary permissions. The log shows that the process is executed correctly.
**Solution**: The error seems to be a discrepancy between the permissions associated with the document, particularly related to the superadmin role. Double-check the permissions and role designation for the user to ensure they have the required access levels for document updates.