refactor: streamline authorization header validation in useConnection hook
This commit is contained in:
parent
30f9855fd5
commit
0da5bc2a2e
1 changed files with 6 additions and 15 deletions
|
|
@ -400,12 +400,13 @@ export function useConnection({
|
||||||
// Use custom headers (migration is handled in App.tsx)
|
// Use custom headers (migration is handled in App.tsx)
|
||||||
let finalHeaders: CustomHeaders = customHeaders || [];
|
let finalHeaders: CustomHeaders = customHeaders || [];
|
||||||
|
|
||||||
|
const isEmptyAuthHeader = (header: CustomHeaders[number]) =>
|
||||||
|
header.name.trim().toLowerCase() === "authorization" &&
|
||||||
|
header.value.trim() === "Bearer";
|
||||||
|
|
||||||
// Check for empty Authorization headers and show validation error
|
// Check for empty Authorization headers and show validation error
|
||||||
const hasEmptyAuthHeader = finalHeaders.some(
|
const hasEmptyAuthHeader = finalHeaders.some(
|
||||||
(header) =>
|
(header) => header.enabled && isEmptyAuthHeader(header),
|
||||||
header.enabled &&
|
|
||||||
header.name.trim().toLowerCase() === "authorization" &&
|
|
||||||
(!header.value.trim() || header.value.trim() === "Bearer"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (hasEmptyAuthHeader) {
|
if (hasEmptyAuthHeader) {
|
||||||
|
|
@ -417,17 +418,7 @@ export function useConnection({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we need to inject OAuth token
|
const needsOAuthToken = finalHeaders.length === 0 || hasEmptyAuthHeader;
|
||||||
// This handles both empty headers and default "Bearer " placeholder headers
|
|
||||||
const isEmptyAuthHeader = (header: CustomHeaders[number]) =>
|
|
||||||
header.name.trim().toLowerCase() === "authorization" &&
|
|
||||||
header.value.trim() === "Bearer";
|
|
||||||
|
|
||||||
const needsOAuthToken =
|
|
||||||
finalHeaders.length === 0 ||
|
|
||||||
finalHeaders.some(
|
|
||||||
(header) => header.enabled && isEmptyAuthHeader(header),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (needsOAuthToken) {
|
if (needsOAuthToken) {
|
||||||
const oauthToken = (await serverAuthProvider.tokens())?.access_token;
|
const oauthToken = (await serverAuthProvider.tokens())?.access_token;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue