Back

Getting CORS error in update Document but i am able to create document.

  • 0
  • Databases
  • Web
Aditya
14 Jul, 2024, 15:42

async createProfile({ email, name, userid, profilephoto, rating = 0, level }) { try { // console.log(email) const session = await this.databases.createDocument( conf.appwriteDatabaseId, conf.appwriteCollectionId, ID.unique(), { userid, profilephoto, rating, level, name, email, } ) return session } catch (err) { console.log("error at createProfile", err) } }

TypeScript
async updateProfile(id, { email, name, profilephoto, rating, level }) {
    try {
        // console.log(userid);
        return await this.databases.updateDocument(
            conf.appwriteDatabaseId,
            conf.appwriteCollectionId,
            id,
            {
                profilephoto,
                rating,
                level,
                name,
                email,
            }
        )
    } catch (err) {
        console.log("error at updateProfile", err)
    }
}   This is code to create and update document. Getting cors error:Access to fetch at 'https://cloud.appwrite.io/v1/databases/66921baf003454626d41/collections/66921bba002560aefc33/documents/66928c3e003018c200da' from origin 'http://localhost:5173' has been blocked by CORS policy: Method PATCH is not allowed by Access-Control-Allow-Methods in preflight response.Understand this error

client.ts:429

TypeScript
   PATCH https://cloud.appwrite.io/v1/databases/66921baf003454626d41/collections/66921bba002560aefc33/documents/66928c3e003018c200da net::ERR_FAILED
TL;DR
Developers experiencing CORS error when trying to update documents but not when creating them. The issue seems to be related to Access-Control-Allow-Methods. Suggested solutions include properly setting up CORS platform and checking domain settings in the appwrite console. Disable CORS by using --disable-web-security and --user-data-dir flags in Chrome for testing purposes. Helpful link provided: https://appwrite.io/blog/post/cors-error.
D5
15 Jul, 2024, 12:14

Do you have added your domain to the appwrite console?

D5
15 Jul, 2024, 12:15

I recommend checking this: https://appwrite.io/blog/post/cors-error

Aditya
19 Jul, 2024, 04:59

Everyone is telling me the same thing to set up platform. So it is proof I have done that. I can work with project, do everything but not in normal Chrome. I am getting CORS in chrome. --disable-web-security and --user-data-dir flags. I used these commands to disable cors and project is perfectly okay

Aditya
19 Jul, 2024, 05:01

It means that project I'd and other details are perfectly fine. But when I run on normal Chrome which everyone is using in the world then I am getting CORS. So what is use of such thing which doesn't work in normal scenario

D5
19 Jul, 2024, 08:09

Where are you deploying the app?

pranay raj
21 Jul, 2024, 22:00

I have added the correct domian name i get an error of Access-Control-Allow-Methods kindly help me out in this

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