I am running my FastAPI server on 127.0.0.1:8000 and my Nextjs frontend on localhost:3000. When I send cookies from the server to the frontend, I can see the response contains the cookies I want. However, they are stored under 127.0.0.1:8000 instead of localhost:3000, so when I make a request with axios from the frontend, cookies are not sent back to the server. What should I do to have the cookies under localhost:3000 instead of the server's url? I have checked several questions about this and played around with the domain field, httponly, etc. without any success. My current FastAPI configuration is the following:
origins = [
"http://localhost",
"http://localhost:3000"
]
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
And I set cookies like:
response.set_cookie(
key="authzRefreshToken",
value=tokens['refresh_token'],
httponly=False,
expires=refresh_token_cookie_expire_date,
samesite= 'strict' if IS_PRODUCTION else 'none',
path="/"
)
Here I place some screenshot where it can be seen cookies are not stored under frontend url and the other image is the server's response.
https://postimg.cc/zLCsMHrc https://postimg.cc/phkgVNyQ
Thank you in advance and regards