-
-
Notifications
You must be signed in to change notification settings - Fork 275
Open
Labels
bug π₯Something isn't workingSomething isn't workingclientClient package relatedClient package related
Description
Description
When setting the authParameters in
| await setAuthParams({ |
the object mutates, but the changes are not persisted, when I print out the authorization headers in setAuthParams, they are set, but not after the call.
With a workaround like this it will be sent correctly
const beforeRequest = async (options: RequestOptions) => {
// Build a temporary options object so we can apply auth headers
// before constructing the immutable HttpRequest. IMPORTANT: do
// not pass a shallow spread to setAuthParams because that would
// prevent mutations from being visible to the caller.
const preOpts: any = {
..._config,
...options,
headers: mergeHeaders(_config.headers, options.headers),
httpClient: options.httpClient ?? _config.httpClient,
serializedBody: undefined,
};
if (preOpts.body !== undefined && preOpts.bodySerializer) {
preOpts.serializedBody = preOpts.bodySerializer(preOpts.body);
}
// remove Content-Type header if body is empty to avoid sending invalid requests
if (preOpts.body === undefined || preOpts.serializedBody === "") {
preOpts.headers = preOpts.headers.delete
? preOpts.headers.delete("Content-Type")
: preOpts.headers;
}
if (preOpts.security) {
// Pass the same object so setAuthParams can mutate it.
await setAuthParams(preOpts);
// Log the updated header after mutation
console.log(preOpts.headers?.getAll("Authorization"));
}
// Now create the actual request using the updated headers
const { opts, req, url } = requestOptions({ ...options, headers: preOpts.headers });
if (opts.requestValidator) {
await opts.requestValidator(opts);
}
return { opts, req, url };
};Reproducible example or configuration
https://stackblitz.com/edit/hey-api-client-fetch-example
OpenAPI specification (optional)
No response
System information (optional)
No response
Metadata
Metadata
Assignees
Labels
bug π₯Something isn't workingSomething isn't workingclientClient package relatedClient package related