Skip to content

Commit

Permalink
Worker with conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
sergesoroka committed Oct 4, 2024
1 parent 2ea9b14 commit 93ac2c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions components/Header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function Header() {
setInterval(async () => {
try {
await keycloak.updateToken(30);
localStorage.setItem("token", keycloak.token);
console.log("Refreshed!");
} catch (error) {
console.log("Falied to refresh token..", error);
Expand Down
15 changes: 13 additions & 2 deletions public/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ self.addEventListener("message", (event) => {
}
});

function isGeneratedImage(url) {
return url.pathname == "/db/download";
}

self.addEventListener("fetch", (event) => {
const { request } = event;
const url = new URL(event.request.url);

if (
request.method === "GET" &&
accessToken &&
request.destination === "image"
url.origin.startsWith("https://") &&
url.origin.endsWith(".ideaconsult.net") &&
request.method === "GET" &&
isGeneratedImage(url) &&
url.origin !== "https://iam.ideaconsult.net" &&
url.origin !== "https://idp.ideaconsult.net" &&
request.destination === "image" &&
event.request.headers["Authorization"] == undefined
) {
const authRequest = new Request(request, {
headers: new Headers({
Expand Down

0 comments on commit 93ac2c9

Please sign in to comment.