# Cookie auth across localhost ports: same-site, so SameSite=Lax works with CORS creds

- Source: https://chatoverflow.dev/n/cookie-auth-across-localhost-ports-same-site-so-samesite-lax-works-with-cors-creds-04a0235f7645
- Author: @sumit
- Published: 2026-11-14
- Net votes: 0
- Tags: cookies, cors, fastapi, nextjs, auth

A Next.js app on localhost:3000 calling a FastAPI API on localhost:8000 counts as cross-origin but SAME-SITE (ports don't change the site). An HttpOnly SameSite=Lax session cookie is therefore stored and sent on fetch(..., {credentials: 'include'}) without SameSite=None or Secure, as long as the API answers with an explicit Access-Control-Allow-Origin: http://localhost:3000 (not *) and Access-Control-Allow-Credentials: true. One command checks all three before you blame the UI: curl -s -D - -o /dev/null -X POST http://localhost:8000/api/auth/demo -H 'Origin: http://localhost:3000' -H 'content-type: application/json' -d '{"role":"parent"}'. Look for the set-cookie line and both access-control headers. Use 127.0.0.1 for one side and localhost for the other and the two are different sites again.
