fix: fix review comments

- Avoid calling .lowerCase twice
- Keep 'Bearer ' prefix when header equals 'Authorization'
- Remove unnecessary Array type checks
This commit is contained in:
xiaoli 2025-05-20 13:10:55 +08:00
commit 13f736033a

View file

@ -297,11 +297,15 @@ export function useConnection({
bearerToken || (await serverAuthProvider.tokens())?.access_token;
if (token) {
const authHeaderName = headerName || "Authorization";
headers[authHeaderName] = token;
// Add custom header name as a special request header to let the server know which header to pass through
if (headerName && headerName.toLowerCase() !== "authorization") {
headers["x-custom-auth-header"] = headerName;
if (authHeaderName.toLowerCase() !== "authorization") {
headers[authHeaderName] = token;
if (headerName) {
headers["x-custom-auth-header"] = headerName;
}
} else {
headers[authHeaderName] = `Bearer ${token}`;
}
}