Clean up fetch code

This commit is contained in:
Gigiaj 2025-06-08 20:05:28 -05:00
parent 3b62beabf1
commit 1d4864592f

View file

@ -65,11 +65,11 @@ self.addEventListener('fetch', (event: FetchEvent) => {
}
event.respondWith(
(async (): Promise<Response> => {
console.log('Unironic race condition mitigation it seems.');
const client = await self.clients.get(event.clientId);
let token: string | undefined;
if (client) token = await askForAccessToken(client);
return fetch(url, fetchConfig(token));
const token: string = await sendAndWaitForReply(client, 'token', {});
const response = await fetch(url, fetchConfig(token));
return response;
})()
);
});