Skip to content

Commit 6e97f8c

Browse files
committed
fix:removed cookies and authorization check
1 parent a102ed8 commit 6e97f8c

File tree

2 files changed

+27
-45
lines changed

2 files changed

+27
-45
lines changed

src/utils/adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
AxiosResponse,
77
} from "axios";
88

9-
import { axiosToFetchResponse, fetchToAxiosConfig, sanitizeFetchResponseHeader } from "./utils";
9+
import { axiosToFetchResponse, fetchToAxiosConfig } from "./utils";
1010

1111
/**
1212
* Dispatches a request using PostRobot.
@@ -64,7 +64,7 @@ export const dispatchApiRequest = async (
6464
config
6565
)) as AxiosResponse;
6666

67-
return axiosToFetchResponse(axiosResponse, sanitizeFetchResponseHeader);
67+
return axiosToFetchResponse(axiosResponse);
6868
} catch (err: any) {
6969
if (err.response) {
7070
return new Response(err.response?.data, {

src/utils/utils.ts

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -86,54 +86,36 @@ export const fetchToAxiosConfig = (
8686
return axiosConfig;
8787
};
8888

89-
export function axiosToFetchResponse(
90-
axiosRes: AxiosResponse,
91-
sanitizeHeadersFn?: (headers: Record<string, string>) => Record<string, string>
92-
): Response {
89+
export function axiosToFetchResponse(axiosRes: AxiosResponse): Response {
9390
const { data, status, statusText, headers: rawHeaders } = axiosRes;
94-
91+
9592
let body: BodyInit;
96-
let contentType = 'application/json';
97-
98-
if (data instanceof Blob || typeof data === 'string' || data instanceof ArrayBuffer) {
99-
body = data;
100-
contentType = rawHeaders['content-type'] || 'application/octet-stream';
93+
let contentType = "application/json";
94+
95+
if (
96+
data instanceof Blob ||
97+
typeof data === "string" ||
98+
data instanceof ArrayBuffer
99+
) {
100+
body = data;
101+
contentType = rawHeaders["content-type"] || "application/octet-stream";
101102
} else {
102-
body = JSON.stringify(data);
103+
body = JSON.stringify(data);
103104
}
104-
105-
const headersObj = sanitizeHeadersFn
106-
? sanitizeHeadersFn(
107-
Object.fromEntries(
108-
Object.entries(rawHeaders).map(([key, value]) => [key, String(value)])
109-
)
110-
)
111-
: Object.fromEntries(
112-
Object.entries(rawHeaders).map(([key, value]) => [key, String(value)])
113-
);
114-
115-
if (!headersObj['content-type']) {
116-
headersObj['content-type'] = contentType;
105+
106+
const headersObj = Object.fromEntries(
107+
Object.entries(rawHeaders).map(([key, value]) => [key, String(value)])
108+
);
109+
110+
if (!headersObj["content-type"]) {
111+
headersObj["content-type"] = contentType;
117112
}
118-
113+
119114
const responseInit: ResponseInit = {
120-
status,
121-
statusText,
122-
headers: new Headers(headersObj),
115+
status,
116+
statusText,
117+
headers: new Headers(headersObj),
123118
};
124-
119+
125120
return new Response(body, responseInit);
126-
}
127-
128-
export function sanitizeFetchResponseHeader(headers: Record<string, string>): Record<string, string> {
129-
const blocked = ['authorization', 'cookie', 'set-cookie'];
130-
const sanitized: Record<string, string> = {};
131-
132-
for (const [key, value] of Object.entries(headers)) {
133-
if (!blocked.includes(key.toLowerCase())) {
134-
sanitized[key] = value;
135-
}
136-
}
137-
138-
return sanitized;
139-
}
121+
}

0 commit comments

Comments
 (0)