Skip to content

Commit 97c5ce9

Browse files
Sanjar MirakhmedovSanjar Mirakhmedov
authored andcommitted
feat: add withCredentials to request options
1 parent e7db175 commit 97c5ce9

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

packages/http/src/HTTP.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,12 @@ test('options.parseJSON', async () => {
276276

277277
expect(parseJSON).toHaveBeenCalledTimes(2);
278278
});
279+
280+
test('options.withCredentials', async () => {
281+
const { request } = createHTTP();
282+
283+
const response = await request('GET /users', { withCredentials: true });
284+
await expect(response.json()).resolves.toMatchObject({
285+
init: { credentials: 'include' },
286+
});
287+
});

packages/http/src/HTTP.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export function createHTTP({
6767

6868
if (fetcher == null) fetcher = fetch;
6969
if (signal) requestInit.signal = signal;
70+
if (options.withCredentials) requestInit.credentials = 'include';
7071
if (endpoint.body != null) requestInit.body = endpoint.body;
7172

7273
return fetcher(endpoint.url, requestInit).then((response) => {

packages/http/src/HTTPEndpoint.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface HTTPEndpointOptions {
2727
body?: BodyInit;
2828
baseURL?: string;
2929
headers?: Record<string, string>;
30+
withCredentials?: boolean;
3031
}
3132

3233
export type HTTPEndpointTemplate = `${HTTPEndpointMethod} /${string}`;

0 commit comments

Comments
 (0)