Skip to content

Commit

Permalink
fix(core/js-sdk) Add the credentials field in the fetch() only if sup…
Browse files Browse the repository at this point in the history
…ported
  • Loading branch information
sgirones committed Dec 5, 2024
1 parent 223bcff commit be65444
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/core/js-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ const normalizeRequest = (
body = JSON.stringify(body)
}

const isFetchCredentialsSupported = "credentials" in Request.prototype

return {
...init,
headers,
// TODO: Setting this to "include" poses some security risks, as it will send cookies to any domain. We should consider making this configurable.
credentials: config.auth?.type === "session" ? "include" : "omit",
credentials: isFetchCredentialsSupported
? config.auth?.type === "session"
? "include"
: "omit"
: undefined,
...(body ? { body: body as RequestInit["body"] } : {}),
} as RequestInit
}
Expand Down

0 comments on commit be65444

Please sign in to comment.