Skip to content

Commit

Permalink
[#130] Unregister service worker when logged out
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Nov 6, 2024
1 parent e6864db commit 4c20ab3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions frontend/src/lib/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,24 @@ export const getCookie = (name) => {
};

export const deleteCookie = (name) => {
// Unregister service worker
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.getRegistrations()
.then((registrations) => {
for (let registration of registrations) {
registration.unregister().then((success) => {
if (success) {
console.log("Service Worker unregistered");
}
});
}
})
.catch((error) => {
console.error("Error unregistering service worker:", error);
});
}
// EOL unregister service worker

document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; SameSite=Strict;`;
};

0 comments on commit 4c20ab3

Please sign in to comment.