Here's some server code:
TypeScript
import { Client, Account, Databases, Users, Permission, Role, Query, ID } from 'node-appwrite';
export default async ({ req, res, log, error }) => {
if (req.path === "/")
{
const userId = req.headers['x-appwrite-user-id'];
const client = new Client()
.setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(process.env.APPWRITE_API_KEY);
const db = new Databases(client);
const event = req.headers['x-appwrite-event'];
if(event === "users." + userId + ".create")
{
let createUserDoc = await db.createDocument('db', 'users', userId, { name: "null", picture: "null"}, [ Permission.delete(Role.user(userId)) ]);
}
}
return res.json({ status: "complete" });
};```
Now, a few months ago, I was able to set the "delete" permission for that document so that only that specific user could delete it. But now I get this error on the server when I create a user:
Error: Permissions must be one of: (any, guests)
If I change it to Role.any(), there are no errors, but that's not the functionality I want. Am I missing something? I have enabled all scopes for my API key to make sure that's not an issue. How can I make it so that only the user who created that document is the only one who can delete it?
TL;DR
Developers are encountering an error when trying to set specific document permissions using an API key. The error states that permissions must be either "any" or "guests," leading to a limitation in functionality. To resolve this, developers can try manually adding the desired permissions in the Appwrite console instead of relying solely on the code.Recommended threads
- 408 Timeout / Curl Error 7 in Executor w...
Hey everyone, I am losing my mind over a routing loop/timeout issue on a fresh self-hosted setup. I have a single Linux VPS (IP: 45.141.37.105) and one domain (...
- functions returning error 401 in local
I updated to 1.9.0, and the functions that used to work fine in 1.8.1 are now giving me a 401 error. I can't seem to find a solution. If anyone is running versi...
- Docker Compose MongoDB Setup
everythings work fine but the mongodb fails on startup everytime. log: ``` Generating random MongoDB keyfile... /bin/bash: line 9: : No such file or directory ...