Back

[SOLVED] CORS No "Access-Control-Allow-Origin" header error

  • 0
  • Accounts
  • Web
Binyamin
12 Jun, 2023, 12:36

Can you double check that the project ID for the deployed app matches the one where you have added the platform?

TL;DR
Title: [SOLVED] CORS No "Access-Control-Allow-Origin" header error Solution: The issue was due to the missing project ID environment variable in Vercel. After setting the project ID correctly, the CORS error was resolved. It is also recommended not to use an API key in client code.
Guille
12 Jun, 2023, 13:05

Are you using OAuth2 as authentication method?

Sazed
12 Jun, 2023, 16:47

I have only one project in appwrite right now

Sazed
12 Jun, 2023, 16:47

ah, no

Binyamin
12 Jun, 2023, 16:51

It looks like the account sdk was enable to get the project ID.

Binyamin
12 Jun, 2023, 16:53

How have you set the client and account SDK?

Binyamin
12 Jun, 2023, 16:53

Can you share the code?

Sazed
12 Jun, 2023, 17:08

i'm just using the account.create endpoint to register new users

Sazed
12 Jun, 2023, 17:08

yeah, here

Binyamin
12 Jun, 2023, 17:10

Mmm It looks like it should work

Sazed
12 Jun, 2023, 17:10

i did write a function for auth using google, which i just removed

Sazed
12 Jun, 2023, 17:10

Let me see if it works now

Sazed
12 Jun, 2023, 17:21

Yeah, still gives the same error

Binyamin
12 Jun, 2023, 17:32

Here https://github.com/SazedWorldbringer/spotify-tinder-thingy/blob/main/src/lib/utils.js You're loading your project ID.

But the project ID is no in your exported JSON

TypeScript
{
  "spotifyClient": "01606d0148544ec685aeb269e5ae8365",
  "endpoint"     : "https://cloud.appwrite.io/v1",
  "project"      : {}.VITE_APPWRITE_PROJECT,
  "collectionID" : "64775749e643228ccb38",
  "databaseID"   : "64775708cd6262fb6f60",
  "apiKey"       : {}.VITE_APPWRITE_API_KEY
}
Binyamin
12 Jun, 2023, 17:32

So, first double check your .env file for the VITE_APPWRITE_PROJECT variable.

Binyamin
12 Jun, 2023, 17:32

Second, it's best not to use an apiKey in client code.

Sazed
13 Jun, 2023, 14:08

Hey

Sazed
13 Jun, 2023, 14:08

sorry i'm responding this late

Sazed
13 Jun, 2023, 14:09

and thank you! i just hadn't set a project id env variable in vercel

Sazed
13 Jun, 2023, 14:09

also, i'll remember to not use api key in client code, thank you!

Binyamin
13 Jun, 2023, 14:11

👍

Binyamin
13 Jun, 2023, 14:11

So it worked?

Sazed
13 Jun, 2023, 14:15

yup, auth now works from the hosted version of the app

Drake
13 Jun, 2023, 17:58

[SOLVED] CORS No "Access-Control-Allow-Origin" header error

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