Back

CORS error while setting up Appwrite locally for the first time

  • 0
  • Web
vjnvisakh
11 Jun, 2023, 17:42
TypeScript
import { Client, Account, Databases } from 'appwrite';

const client = new Client();
client.setEndpoint("http://localhost/v1").setProject("6485fa6a1da8f");

export const account = new Account(client);
export const databases = new Databases(client);

The host is localhost under platform/host

TL;DR
User is encountering a CORS error while setting up Appwrite locally. The error occurs when trying to log in with email credentials. The user has confirmed that the project ID and API endpoint are correct, and the app is running on localhost:3000. The user has set the hostname in the Appwrite dashboard to "*", but the error still persists. The user has shared a code snippet showing the use of the Appwrite client. The host for the code is set to "localhost" under platform/host. Solution: Check if the project ID is correct and ensure that the host address in the browser matches the one specified in the code.
Binyamin
11 Jun, 2023, 17:57

What is your host address ii the browser?

Binyamin
11 Jun, 2023, 17:58

Meaning what is the browser URL when you're runnig this code

Drake
11 Jun, 2023, 18:10

CORS error while setting up Appwrite locally for the first time

Drake
11 Jun, 2023, 18:10

Would you please also double check the project ID is correct?

Kunal Virk
25 Jun, 2023, 19:27

,Hi, I am using refine.dev/next.js with AppWrite. I have just set up the authentication but I am getting "CORS" error. I have checked that the projectID and API_Endpoint are correct. I am running my app on localhost:3000. Also, in the appwrite dashboard, I have set the hostname to * to test and still it throws the CORS error.

Drake
25 Jun, 2023, 23:57

Please share the full exact logs/errors and network logs

Kunal Virk
26 Jun, 2023, 08:21

Hi, Here is the full error:

TypeScript
Access to XMLHttpRequest at 'https://cloud.appwrite.io/v1/account/sessions/email' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
browser-ponyfill.js:518     POST https://cloud.appwrite.io/v1/account/sessions/email net::ERR_FAILED 401

This happens when I try to log in with my email credentials.

Drake
26 Jun, 2023, 11:53

Wait sorry please create a new post rather than reusing an older post

Kunal Virk
26 Jun, 2023, 11:57

Cool, I will create a new post Thanks

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