Back

[SOLVED] CORS Error - No 'access-control-allow-origin'

  • 0
  • Web
  • Cloud
chetan_thakral
6 Jun, 2023, 14:09

I am using appwrite cloud for the first time , and was trying to fetch documents with the help of listDocuments methods but i am getting CORS error in the browser.

const client = new Client(); const databases = new Databases(client); client.setEndpoint( "https://cloud.appwrite.io/v1/databases/databaseID/collections/collectionId/documents" ); client.setProject(appwrite_project_id);

TypeScript
  const promise = databases.listDocuments(
    databaseId,
    colectionId
  );
  promise
    .then(function (response) {
      console.log(response);
    })
    .catch(function (error) {
      console.log(error);
    });

This is the code that I am using. The error i am getting :

TL;DR
The user initially had a CORS error, which was resolved by updating permissions in the collection settings. However, they encountered a different error, and despite trying multiple solutions and suggestions from other users, the error persisted. The user also inquired about setting request headers, but found no information in the documentation. No solution was provided for this issue.
chetan_thakral
6 Jun, 2023, 14:12

This is the hostname I have used in the appwrite dashboard.

Binyamin
6 Jun, 2023, 14:14

Try to change the endpoint to this

TypeScript
const client = new Client().setEndpoint('https://cloud.appwrite.io/v1')
Binyamin
6 Jun, 2023, 14:14

The rest of the path will be enter by the function it self, in your case the listDocuments for example.

chetan_thakral
6 Jun, 2023, 14:15

Hey thanks for replying , but I am still facing the same issue.

Binyamin
6 Jun, 2023, 14:18

Recheck the appwrite_project_id

chetan_thakral
6 Jun, 2023, 14:20

Rechecked! But still the error persists.

chetan_thakral
6 Jun, 2023, 14:21

By the way , is there any way i can set request headers ? I have gone over the docs but didnt found anything.

Binyamin
6 Jun, 2023, 14:34

If you're using the SDK then you can't

Binyamin
6 Jun, 2023, 14:34

Can you share the error now?

chetan_thakral
6 Jun, 2023, 14:34

yeah , i am using appwrite sdk

chetan_thakral
6 Jun, 2023, 14:35

Still i am getting the same error.

Binyamin
6 Jun, 2023, 14:38

Sometime it can happened because of the double slash,

Binyamin
6 Jun, 2023, 14:38

Can you make sure there's only one?

chetan_thakral
6 Jun, 2023, 14:41

Thanks , that error is resolved, now i am getting a different error

Binyamin
6 Jun, 2023, 14:43

Okay, for that you'll need to make sure that your collection has set permissions for that user

Binyamin
6 Jun, 2023, 14:44

You can go to your collection settings and check over there.

chetan_thakral
6 Jun, 2023, 14:47

I have updated the permissions for both specific users and any user , but still the same error is coming.

chetan_thakral
6 Jun, 2023, 14:47
Binyamin
6 Jun, 2023, 14:50

You get the same not authorized error?

chetan_thakral
6 Jun, 2023, 14:59

Yes

Binyamin
7 Jun, 2023, 12:59

You still facing the error?

chetan_thakral
7 Jun, 2023, 19:10

No , it is fixed now , thanks for the help.

Binyamin
7 Jun, 2023, 19:11

<:appwriteupvote:899677724615016528>

Drake
7 Jun, 2023, 19:38

[SOLVED] CORS Error - No 'access-control-allow-origin'

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