diff --git a/apps/oauth/package.json b/apps/oauth/package.json index c73873582c..d4bdcdd0eb 100644 --- a/apps/oauth/package.json +++ b/apps/oauth/package.json @@ -1,7 +1,7 @@ { "name": "@umami/oauth", "files": [ - "public/redirect.html" + "public/sw.js", ], "devDependencies": { "depcheck": "^1.4.7", diff --git a/apps/oauth/public/sw.js b/apps/oauth/public/sw.js new file mode 100644 index 0000000000..62fc15b434 --- /dev/null +++ b/apps/oauth/public/sw.js @@ -0,0 +1,347 @@ +/* eslint-disable */ +function getScope() { + return self.registration.scope; +} + +self.addEventListener("message", function (event) { + if (event.data && event.data.type === "SKIP_WAITING") { + self.skipWaiting(); + } +}); + +self.addEventListener("fetch", function (event) { + try { + const url = new URL(event.request.url); + if (url.pathname.includes("redirect") && url.href.includes(getScope())) { + event.respondWith( + new Response( + new Blob( + [ + ` + + +
+ + + +