Skip to content

Commit 0da5bc2

Browse files
committed
refactor: streamline authorization header validation in useConnection hook
1 parent 30f9855 commit 0da5bc2

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

client/src/lib/hooks/useConnection.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,13 @@ export function useConnection({
400400
// Use custom headers (migration is handled in App.tsx)
401401
let finalHeaders: CustomHeaders = customHeaders || [];
402402

403+
const isEmptyAuthHeader = (header: CustomHeaders[number]) =>
404+
header.name.trim().toLowerCase() === "authorization" &&
405+
header.value.trim() === "Bearer";
406+
403407
// Check for empty Authorization headers and show validation error
404408
const hasEmptyAuthHeader = finalHeaders.some(
405-
(header) =>
406-
header.enabled &&
407-
header.name.trim().toLowerCase() === "authorization" &&
408-
(!header.value.trim() || header.value.trim() === "Bearer"),
409+
(header) => header.enabled && isEmptyAuthHeader(header),
409410
);
410411

411412
if (hasEmptyAuthHeader) {
@@ -417,17 +418,7 @@ export function useConnection({
417418
});
418419
}
419420

420-
// Check if we need to inject OAuth token
421-
// This handles both empty headers and default "Bearer " placeholder headers
422-
const isEmptyAuthHeader = (header: CustomHeaders[number]) =>
423-
header.name.trim().toLowerCase() === "authorization" &&
424-
header.value.trim() === "Bearer";
425-
426-
const needsOAuthToken =
427-
finalHeaders.length === 0 ||
428-
finalHeaders.some(
429-
(header) => header.enabled && isEmptyAuthHeader(header),
430-
);
421+
const needsOAuthToken = finalHeaders.length === 0 || hasEmptyAuthHeader;
431422

432423
if (needsOAuthToken) {
433424
const oauthToken = (await serverAuthProvider.tokens())?.access_token;

0 commit comments

Comments
 (0)