Back

Unable to properly execute function locally: CORS No Allow Credentials

  • 1
  • Functions
Harrison Lo
25 Dec, 2024, 03:33

I've run appwrite run functions to setup a function locally at localhost:3000. The frontend code at localhost:5173 is making a request to http://localhost:3000/v1/functions/<id>/executions. The function actually runs but could not get any body or bodyJson content. The browser console network row says CORS No Allow Credentials desipte having a status 200. I'm trying to pass a JSON object to the backend but could not figure out how.

TL;DR
Issue: Unable to properly execute function locally due to CORS No Allow Credentials error and missing request body in backend function. Solution: The CORS No Allow Credentials error is likely occurring due to missing CORS headers allowing credentials in the function response. Ensure the backend function includes appropriate CORS headers like `Access-Control-Allow-Origin` and `Access-Control-Allow-Credentials`. Additionally, the missing request body issue in the backend can be resolved by parsing the incoming request data correctly. Check your request parsing logic to properly handle incoming JSON data.
Harrison Lo
25 Dec, 2024, 03:34

Unable to properly execute function locally: CORS No Allow Credentials

Harrison Lo
25 Dec, 2024, 03:50

In the frontend, this is called:

TypeScript
functions.createExecution(<id>, JSON.stringify({ data }))
Harrison Lo
25 Dec, 2024, 03:55

In the backend, log(req.headers) shows:

TypeScript
{
  "host": "127.0.0.1:3000",
  "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:133.0) Gecko/20100101 Firefox/133.0",
  "accept": "*/*",
  "accept-language": "en-US,en;q=0.5",
  "accept-encoding": "gzip, deflate, br, zstd",
  "access-control-request-method": "POST",
  "access-control-request-headers": "content-type,x-appwrite-project,x-appwrite-response-format,x-sdk-language,x-sdk-name,x-sdk-platform,x-sdk-version",
  "referer": "http://localhost:5173/",
  "origin": "http://localhost:5173",
  "dnt": "1",
  "sec-gpc": "1",
  "connection": "keep-alive",
  "sec-fetch-dest": "empty",
  "sec-fetch-mode": "cors",
  "sec-fetch-site": "cross-site",
  "priority": "u=4",
  "x-appwrite-key": "dynamic...",
  "x-appwrite-trigger": "http",
  "x-appwrite-event": "",
  "x-appwrite-user-id": "",
  "x-appwrite-user-jwt": ""
}

while log(req.bodyText) would be empty, and log(JSON.stringify(req.bodyJson)) would throw SyntaxError: Unexpected end of JSON input 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