Skip to content

Commit 13f7360

Browse files
committed
fix: fix review comments
- Avoid calling .lowerCase twice - Keep 'Bearer ' prefix when header equals 'Authorization' - Remove unnecessary Array type checks
1 parent 618f24a commit 13f7360

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

client/src/lib/hooks/useConnection.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,15 @@ export function useConnection({
297297
bearerToken || (await serverAuthProvider.tokens())?.access_token;
298298
if (token) {
299299
const authHeaderName = headerName || "Authorization";
300-
headers[authHeaderName] = token;
301300

302301
// Add custom header name as a special request header to let the server know which header to pass through
303-
if (headerName && headerName.toLowerCase() !== "authorization") {
304-
headers["x-custom-auth-header"] = headerName;
302+
if (authHeaderName.toLowerCase() !== "authorization") {
303+
headers[authHeaderName] = token;
304+
if (headerName) {
305+
headers["x-custom-auth-header"] = headerName;
306+
}
307+
} else {
308+
headers[authHeaderName] = `Bearer ${token}`;
305309
}
306310
}
307311

server/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ const createTransport = async (req: express.Request): Promise<Transport> => {
9595
// If the header "x-custom-auth-header" is present, use its value as the custom header name.
9696
if (req.headers["x-custom-auth-header"] !== undefined) {
9797
const customHeaderName = req.headers["x-custom-auth-header"] as string;
98-
if (req.headers[customHeaderName.toLowerCase()] !== undefined) {
99-
const value = req.headers[customHeaderName.toLowerCase()];
100-
headers[customHeaderName] = Array.isArray(value) ? value[value.length - 1] : value as string;
98+
if (req.headers[customHeaderName] !== undefined) {
99+
const value = req.headers[customHeaderName];
100+
headers[customHeaderName] = value as string;
101101
}
102102
}
103103

@@ -132,9 +132,9 @@ const createTransport = async (req: express.Request): Promise<Transport> => {
132132
// If the header "x-custom-auth-header" is present, use its value as the custom header name.
133133
if (req.headers["x-custom-auth-header"] !== undefined) {
134134
const customHeaderName = req.headers["x-custom-auth-header"] as string;
135-
if (req.headers[customHeaderName.toLowerCase()] !== undefined) {
136-
const value = req.headers[customHeaderName.toLowerCase()];
137-
headers[customHeaderName] = Array.isArray(value) ? value[value.length - 1] : value as string;
135+
if (req.headers[customHeaderName] !== undefined) {
136+
const value = req.headers[customHeaderName];
137+
headers[customHeaderName] = value as string;
138138
}
139139
}
140140

0 commit comments

Comments
 (0)