
Hello, i get the following error when trying to access the createEmailSession endpoint in the client sdk:
Access to XMLHttpRequest at 'http://192.168.x.x/v1/account/sessions/email' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I have added both localhost and * as web platforms.
The client is initialized like so:
client.setProject("64d...196").setEndpoint("http://192.168.x.x/v1")```

you should probably use https instead of just http. Also, make sure your project ID is correct. share more of the network logs if you're still having trouble

Should i use https even though im working in dev environment on localhost?

i typically do

and i just accept the self signed cert

Thanks for the tip
Seems its messed up on both the client SDK and server SDK.. I get this huge error on the server SDK when trying to call account.get() :
at Client.call (/usr/local/server/src/function/node_modules/node-appwrite/lib/client.js:172:31)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Account.get (/usr/local/server/src/function/node_modules/node-appwrite/lib/services/account.js:29:16)
at async APIContext.isUserValid (file:///usr/local/server/src/function/src/functions/api/code/APIContextClass.js:52:16)
at async APIContext.setUserObject (file:///usr/local/server/src/function/src/functions/api/code/APIContextClass.js:33:29)
at async Module.default (file:///usr/local/server/src/function/src/functions/api/code/main.js:19:9)
at async execute (/usr/local/server/src/server.js:141:22)
at async /usr/local/server/src/server.js:158:13 {
code: 401,
type: '',
response: '<!DOCTYPE

People typically don't use account.get() with a server SDK...what are you doing?

Im basically verifying the user request jwt on the server, and with it, getting their role, which is used to have more fine-grained control of what can be accessed. Since the error appeared i havent changed any code, however, i did upgrade from 1.4.2 -> 1.4.3 -> 1.4.4

Try to set the IP address as the domain environment variables in your Appwrite .env file

Both APP_DOMAIN and APP_DOMAIN_TARGET?

Well that worked.. Shouldn't it be working on localhost as well then?

yes, it should

I get connect ECONNREFUSED 127.0.0.1:80
when using localhost, trying to execute my function

you're using localhost from within an Appwrite Function?

When setting the client in the function like so:
const client = new Client()
.setProject('projectID')
.setEndpoint("http://localhost/v1")
.setKey(process.env.APPWRITE_APIFUNC_KEY)

and then i get the above error when calloing account.get()

inside an appwrite function, you cannot use localhost because the runtime container will try to connect to itself instead of appwrite

on the host machine, you can browse to https://localhost to see the appwrite console

Exactly, thats why i originally changed it to use the ipv4 adresse in the functions, which had previously worked fine until upgrading to 1.4.4. Now im getting the CORS error when trying to execute functions from the client side hosted on localhost:3000

if you're appwrite instance is installed locally, you can use localhost from your client app. You just can't use it in an appwrite function

Hm i cant seem to get it working with localhost as the domain and functions using the ipv4 address, no matter what i try i get the above errors. Only way i can make it work is by pointing everything to the ipv4 address. I guess thats what im gonna have to do

in your appwrite function, you must use ip or domain because you cannot use localhost

what is your problem using localhost from your web app?

Since just using the ipv4 across the board worked fine, i just wrote some scripts that configure everything automatically with the given ipv4 of the local machine. Thank you for your help π

[SOLVED] CORS error on client SDK localhost
Recommended threads
- Google login error: {"message":"Invalid ...
hi, im trying to use google login with account.createOAuth2Session( 'google', 'profevardilla.pages.dev', 'profevardilla.pages.dev'...
- Auth Error
"use client"; import { useEffect } from "react"; import { getSessionCookie } from "@/actions/auth"; import { createBrowserSessionClient } from "@/lib/appwrite-...
- Prevent modifying specific attributes
How do I prevent user to only to be able to modify some of the attributes. Document level security gives full access to update whole document, what are the wor...
