Back

CORS Error no matter what

  • 0
  • Self Hosted
  • Auth
  • Web
xmaniaxz
4 Jan, 2025, 17:18

I am trying to set up a simple authentication from a project i used before which used node-appwrite with appwrite on version 1.5.1

I updated to 1.6.0 after some troubles but now i can't seem to make a request without crashing into CORS.

errors:

TypeScript
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://appwrite.lostcausenetwork.com/v1/account/sessions/email. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 301.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://appwrite.lostcausenetwork.com/v1/account/sessions/email. (Reason: CORS request did not succeed). Status code: (null).

code:

TypeScript
import { Client,Account, Models } from "node-appwrite";


const CreateAdminClient = async (): Promise<Client> => {
    const client = new Client();
    const endpoint: string = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!;
    const projectId:string = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID!;
    const secretKey:string = process.env.NEXT_PUBLIC_APPWRITE_API_KEY!;

    client
        .setEndpoint(endpoint)
        .setProject(projectId)
        .setKey(secretKey);
    return client;
}

const CreateAdminAccount = async (): Promise<Account> => {
    const account = new Account(await CreateAdminClient());
    return account;
}

export const logUserIn = async (email: string, password: string): Promise<Models.Session> => {
    const account = await CreateAdminAccount(); 
    const session = await account.createEmailPasswordSession(email, password);

    return session;
}```
TL;DR
Developers are encountering CORS errors when making requests to an API using node-appwrite. The issue seems to be related to missing CORS headers. **Solution:** To fix the CORS issue, you need to ensure that the API server includes the appropriate CORS headers, such as 'Access-Control-Allow-Origin', in its response.
xmaniaxz
4 Jan, 2025, 17:38

web platform is also set up. though that shouldnt matter since i am using an api key

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