Skip to content

Commit dfb73cc

Browse files
authored
💥 By default, do not set credentials in fetch (#475)
Follow up to #248 See #469 Do not pass `credentials` to `fetch` unless explicitly requrested. cc @WalshyDev for visibility
1 parent f0e3eff commit dfb73cc

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

‎packages/inference/src/lib/makeRequestOptions.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,14 @@ export async function makeRequestOptions(
8989
return `${HF_INFERENCE_API_BASE_URL}/models/${model}`;
9090
})();
9191

92-
// Let users configure credentials, or disable them all together (or keep default behavior).
93-
// ---
94-
// This used to be an internal property only and never exposed to users. This means that most usages will never define this value
95-
// So in order to make this backwards compatible, if it's undefined we go to "same-origin" (default behaviour before).
96-
// If it's a boolean and set to true then set to "include". If false, don't define credentials at all (useful for edge runtimes)
97-
// Then finally, if it's a string, use it as-is.
92+
/**
93+
* For edge runtimes, leave 'credentials' undefined, otherwise cloudflare workers will error
94+
*/
9895
let credentials: RequestCredentials | undefined;
9996
if (typeof includeCredentials === "string") {
10097
credentials = includeCredentials as RequestCredentials;
101-
} else if (typeof includeCredentials === "boolean") {
102-
credentials = includeCredentials ? "include" : undefined;
103-
} else if (includeCredentials === undefined) {
104-
credentials = "same-origin";
98+
} else if (includeCredentials === true) {
99+
credentials = "include";
105100
}
106101

107102
const info: RequestInit = {
@@ -113,7 +108,7 @@ export async function makeRequestOptions(
113108
...otherArgs,
114109
options: options && otherOptions,
115110
}),
116-
credentials,
111+
...(credentials && { credentials }),
117112
signal: options?.signal,
118113
};
119114

‎packages/inference/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface Options {
3232
signal?: AbortSignal;
3333

3434
/**
35-
* (Default: "same-origin"). String | Boolean. Credentials to use for the request. If this is a string, it will be passed straight on. If it's a boolean, true will be "include" and false will not send credentials at all.
35+
* Credentials to use for the request. If this is a string, it will be passed straight on. If it's a boolean, true will be "include" and false will not send credentials at all (which defaults to "same-origin" inside browsers).
3636
*/
3737
includeCredentials?: string | boolean;
3838
}

0 commit comments

Comments
 (0)