CORS
Cross-Origin Resource Sharing restricts which origins can call your API. The credentials option controls whether cookies are sent.
Cross-Origin Resource Sharing restricts which origins can call your API. The credentials option controls whether cookies are sent.
// Same-origin: cookies sent by default
await fetch("/api/data");
// Cross-origin with cookies
await fetch("https://api.example.com/data", { credentials: "include" });
// No credentials (default for cross-origin)
await fetch("https://api.example.com/data", { credentials: "omit" });
// Server must respond with: Access-Control-Allow-Origin: https://your-site.com
// Access-Control-Allow-Credentials: true
credentials: "include" requires the server to respond with specific CORS headers — * is not allowed.
More in JavaScript