FastAPI CORS scenarios When Accessing Endpoint from React Frontend with Credentials
I'm optimizing some code but I've been banging my head against this for hours..... I'm working with a CORS scenario in my FastAPI application when trying to access an API endpoint from my React frontend. The FastAPI server is set up to allow CORS, but it seems that the credentials are not being accepted, leading to a `CORS: Missing 'Access-Control-Allow-Credentials' header` behavior. I'm using FastAPI version 0.68.2 and the `fastapi.middleware.cors` module to configure CORS. Here's how I've set it up: ```python from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware app = FastAPI() app.add_middleware( CORSMiddleware, allow_origins=["http://localhost:3000"], # React app URL allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) @app.get("/data") async def get_data(): return {"message": "Success"} ``` On the React side, I am making a request like this: ```javascript fetch('http://localhost:8000/data', { method: 'GET', credentials: 'include', // Important for sending cookies }) .then(response => response.json()) .then(data => console.log(data)) .catch(behavior => console.behavior('behavior:', behavior)); ``` When I run the React app and try to access the endpoint, I see this behavior in the console: `Access to fetch at 'http://localhost:8000/data' 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-Credentials' header is present on the requested resource.` I've tried enabling `allow_credentials=True` and checking that both servers are running in the same environment (i.e., both on localhost) but it's still not working. Is there something I am overlooking, or could it be an scenario with how FastAPI handles CORS with credentials? I'm working on a API that needs to handle this. I'm working on a web app that needs to handle this. This is happening in both development and production on Debian. Any pointers in the right direction?