Skip to content
Back

Error: Permissions must be one of: (any, guests)

  • 1
  • Self Hosted
  • Functions
  • Web
m0hsin_
2 Feb, 2024, 14:29

How can I update the permissions of a document using cloud functions, the code below gives me the aforementioned error:

`import { Client, Databases, Permission, Query, Role } from 'node-appwrite';

export default async function ({ req, res }) {

TypeScript
console.log(req);
const client = new Client()
    .setEndpoint(process.env.REACT_APP_APPWRITE_BASE_URL)
    .setProject(process.env.REACT_APP_APPWRITE_PROJECT_KEY);

const database = new Databases(client);

try{
    const team = "xxx";
    const response = await database.updateDocument(
        process.env.REACT_APP_APPWRITE_DATABASE_ID,
        process.env.REACT_APP_APPWRITE_COMPANIES_COLLECTION_ID,
        "yyy",
        {},
        [              
            Permission.read(Role.team("team:" + team)),   
            Permission.update(Role.team("team:" + team)),  
            Permission.delete(Role.team("team:" + team))  
        ]
    );
}catch (error) {
    console.log(error);
}

};

TL;DR
Developers are experiencing an error related to permissions. The error message states that permissions must be one of: (any, guests). Another developer suggests checking the code and provides a link to the documentation. The documentation shows that the team ID should be used without "team:" prefix. The original code is updated accordingly, but the issue persists. Another developer suggests using `Permissions.Write(Role.Team(team))` if all permissions are going to the same team. The updated code is provided in the thread. TL;DR: Developers are getting an error related to permissions. They update the code according to the documentation, but the issue persists. Another developer
Kenny
2 Feb, 2024, 14:32

If these are all going to the same team you can just do

Permissions.Write(Role.Team(team))

m0hsin_
2 Feb, 2024, 14:33

Thanks for the tip @Kenny . This was my initial setup and I was still getting the same issue

Kenny
2 Feb, 2024, 14:33

https://appwrite.io/docs/advanced/platform/permissions#example-1-basic-usage

Looking at the docs, you don't have to do team:team_id

It's just the team_id. So with your current setup it would be.

TypeScript
[
    Permission.read(Role.team(team)),
    Permission.update(Role.team(team)),
    Permission.delete(Role.team(team))
]
Kenny
2 Feb, 2024, 14:34

Were you doing "team:"+team? I believe it would just be team

m0hsin_
2 Feb, 2024, 14:51

Yes, here is the updated code:

`import { Client, Databases, Permission, Query, Role } from 'node-appwrite';

export default async function ({ req, res }) {

TypeScript
console.log(req);
const client = new Client()
    .setEndpoint(process.env.REACT_APP_APPWRITE_BASE_URL)
    .setProject(process.env.REACT_APP_APPWRITE_PROJECT_KEY);

const database = new Databases(client);

try{
    const team = "xx";
    console.log("The Team is", team);
    const response = await database.updateDocument(
        process.env.REACT_APP_APPWRITE_DATABASE_ID,
        process.env.REACT_APP_APPWRITE_COMPANIES_COLLECTION_ID,
        "yy",
        {},
        [              
            Permission.read(Role.team(team)),   
            Permission.update(Role.team(team)),  
            Permission.delete(Role.team(team))  
        ]
    );
    console.log("Permissions Update", response);
}catch (error) {
    console.log(error);
    throw error;
}

return res.json({ ok: true, message: 'Vote cast.'}); }; `

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more