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:
parent
618f24a9ac
commit
13f736033a
2 changed files with 13 additions and 9 deletions
|
|
@ -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}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,9 +95,9 @@ const createTransport = async (req: express.Request): Promise<Transport> => {
|
|||
// If the header "x-custom-auth-header" is present, use its value as the custom header name.
|
||||
if (req.headers["x-custom-auth-header"] !== undefined) {
|
||||
const customHeaderName = req.headers["x-custom-auth-header"] as string;
|
||||
if (req.headers[customHeaderName.toLowerCase()] !== undefined) {
|
||||
const value = req.headers[customHeaderName.toLowerCase()];
|
||||
headers[customHeaderName] = Array.isArray(value) ? value[value.length - 1] : value as string;
|
||||
if (req.headers[customHeaderName] !== undefined) {
|
||||
const value = req.headers[customHeaderName];
|
||||
headers[customHeaderName] = value as string;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -132,9 +132,9 @@ const createTransport = async (req: express.Request): Promise<Transport> => {
|
|||
// If the header "x-custom-auth-header" is present, use its value as the custom header name.
|
||||
if (req.headers["x-custom-auth-header"] !== undefined) {
|
||||
const customHeaderName = req.headers["x-custom-auth-header"] as string;
|
||||
if (req.headers[customHeaderName.toLowerCase()] !== undefined) {
|
||||
const value = req.headers[customHeaderName.toLowerCase()];
|
||||
headers[customHeaderName] = Array.isArray(value) ? value[value.length - 1] : value as string;
|
||||
if (req.headers[customHeaderName] !== undefined) {
|
||||
const value = req.headers[customHeaderName];
|
||||
headers[customHeaderName] = value as string;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue