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:
1 parent
16663ec813
commit
a7ad809520
1 file changed
+7
-1
@@ -58,11 +58,17 @@ const normalizeRequest = (
|
|||||||
body = JSON.stringify(body)
|
body = JSON.stringify(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isFetchCredentialsSupported = "credentials" in Request.prototype
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...init,
|
...init,
|
||||||
headers,
|
headers,
|
||||||
// TODO: Setting this to "include" poses some security risks, as it will send cookies to any domain. We should consider making this configurable.
|
// 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"] } : {}),
|
...(body ? { body: body as RequestInit["body"] } : {}),
|
||||||
} as RequestInit
|
} as RequestInit
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user