Skip to content

Commit

Permalink
added scope only for production
Browse files Browse the repository at this point in the history
  • Loading branch information
sergesoroka committed Oct 5, 2024
1 parent fdd1910 commit 3a53c6b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
15 changes: 5 additions & 10 deletions public/worker.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
let accessToken = null;

// self.addEventListener("install", (event) => {
// event.waitUntil(
// caches.open("static-v1").then((cache) => {
// return cache.addAll(["/search"]);
// })
// );
// self.skipWaiting();
// });
self.addEventListener("install", (event) => {
self.skipWaiting();
});

self.addEventListener("activate", (event) => {
event.waitUntil(clients.claim());
Expand All @@ -17,7 +12,7 @@ self.addEventListener("activate", (event) => {
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SET_TOKEN") {
accessToken = event.data.token;
console.log("Access token received by Service Worker, public:");
console.log("Access token received by Service Worker:");
}
});

Expand Down Expand Up @@ -50,7 +45,7 @@ self.addEventListener("fetch", (event) => {
// isGeneratedImage(url) &&
url.origin !== "https://iam.ideaconsult.net" &&
url.origin !== "https://idp.ideaconsult.net" &&
request.destination === "image" &&
// request.destination === "image" &&
event.request.headers["Authorization"] == undefined
) {
const authRequest = new Request(request, {
Expand Down
3 changes: 2 additions & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ const stored_token = localStorage.getItem("token");
const token = keycloak.token ? keycloak.token : stored_token;

const base_url = import.meta.env.PROD ? "/search/worker.js" : "/worker.js";
const reg_scope = import.meta.env.PROD ? "{ scope: '/search/' }" : null;

console.log("base url", base_url);

if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
navigator.serviceWorker
.register(base_url)
.register(base_url, reg_scope)
.then((registration) => {
console.log(
"Service Worker registered with scope: ",
Expand Down
22 changes: 11 additions & 11 deletions utils/useFetch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ function useFetch(url) {
headers: { "Content-Type": "application/json" },
});

axiosInstance.interceptors.request.use(
function (config) {
if (kc_token) {
config.headers.Authorization = `Bearer ${kc_token}`;
}
return config;
},
function (error) {
return Promise.reject(error);
}
);
// axiosInstance.interceptors.request.use(
// function (config) {
// if (kc_token) {
// config.headers.Authorization = `Bearer ${kc_token}`;
// }
// return config;
// },
// function (error) {
// return Promise.reject(error);
// }
// );

useEffect(() => {
if (keycloak.authenticated) {
Expand Down

0 comments on commit 3a53c6b

Please sign in to comment.