fix(core/js-sdk) Add the credentials field in the fetch() only if supported (#10446)
fixes https://github.com/medusajs/nextjs-starter-medusa/issues/421 The root cause of the issue is that credentials is not supported by CloudFlare workers.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user