Back

[Solved] Unauthorized on a completely public collection

  • 0
  • Databases
fafa
20 Nov, 2023, 17:44

Hello,

I was trying to access the user their own document, which was made using document security and that is working perfectly.

However, now I want to fetch the data, but it only gives me 401 errors.. Using the cookies doesn't work, creating a JWT doesn't work and the only thing that does work is using a X-Appwrite-Key, which doesn't make sense. Any help is appreciated.

TL;DR
The user is facing unauthorized access issues while trying to fetch data from a completely public collection. The user has tried using cookies and JWT but it only works when using X-Appwrite-Key. The solution is to check if there is a relationship in the collection that the user does not have access to. Once that is resolved, the unauthorized error should be resolved. Additionally, the user mentions that Postman does not work for fetching.
fafa
20 Nov, 2023, 17:45

My code:

TypeScript
   const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/v1/databases/databaseid/collections/collectionid/documents`, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
        "X-Appwrite-Project": `${process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID}`,
        "X-Appwrite-Response-Format": "1.4.0",
      },
    });
fafa
20 Nov, 2023, 17:45

The error:

TypeScript
{
  message: 'The current user is not authorized to perform the requested action.',
  code: 401,
  type: 'user_unauthorized',
 }
fafa
20 Nov, 2023, 17:46

I even have my entire collection on read all..

fafa
20 Nov, 2023, 18:01

(Postman also doesn't work fetching, FYI)

fafa
20 Nov, 2023, 18:25

Found it.. seems that there was a relationship which the user didn't have access to..

fafa
20 Nov, 2023, 18:25

[Solved] Unauthorized on a completely public collection

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