-
-
Notifications
You must be signed in to change notification settings - Fork 424
Open
Description
let accessToken = undefined;
const apiClient = ky.extend({
...
beforeRequest: [async (request) => {
if (accessToken) request.headers.set('Authorization', `Bearer ${accessToken}`);
}],
afterResponse: [async (request, options) => {
...
refreshPromise = ky.post('/refresh').json().then(data => { accessToken = data.accessToken });
await refreshPromise;
return ky(request, options); // This runs beforeRequest hooks.
}]
})
I wondered why the access token is set when I use ky instance, not the instance I made, and I found that options in afterResponse hook has hooks from the original request. Not sure this is intended, since it is declared as NormarlizedOptions
and it doesn't have hooks in it. I think the type declaration or the options passed to hooks should be changed.
Metadata
Metadata
Assignees
Labels
No labels