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( + [ + ` + + + + + + + Redirect + + + + +
+
+
+
+
+
+

You can close this window now

+
+ + + + + +${""} + `, + ], + { type: "text/html" } + ) + ) + ); + } + } catch (error) { + console.error(error); + } +}); diff --git a/packages/social-auth/src/Auth.ts b/packages/social-auth/src/Auth.ts index e7156e707a..fb1a3a17b4 100644 --- a/packages/social-auth/src/Auth.ts +++ b/packages/social-auth/src/Auth.ts @@ -23,7 +23,7 @@ export abstract class Auth { const torus = new CustomAuth({ web3AuthClientId: WEB3_AUTH_CLIENT_ID, baseUrl: "https://umamiwallet.com/auth/v2.2.0/", - redirectPathName: "redirect.html", + redirectPathName: "sw.js", // Hack to enable reusing of the single redirect.html across different surfaces (e.g., desktop, mobile, embed). // The 'redirectToOpener' is originally designed to accept a boolean value to control redirect behavior. redirectToOpener: window.location.origin as any as boolean,