Created
March 13, 2024 11:37
-
-
Save pablof7z/20911e5caa0c61f970f45fec1172e0c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
signer.rpc.on("authUrl", (url: string) => { | |
popup = window.open(url, "_blank", "width=400,height=600"); | |
if (!popup) { | |
popupNotOpened = true; | |
redirectToAuthUrlWithCallback(url); | |
} | |
authUrl = url; | |
let checkPopup = setInterval(() => { | |
if (!popup) { | |
popupNotOpened = true; | |
} | |
if (popup?.closed) { | |
clearInterval(checkPopup); | |
creating = false; | |
} | |
}, 500); // Check every 500ms | |
}); | |
function redirectToAuthUrlWithCallback(url: string) { | |
const redirectUrl = new URL(url); | |
const callbackPath = "/auth/callback"; | |
const currentUrl = new URL(window.location.href); | |
const callbackUrl = new URL(callbackPath, currentUrl.origin); | |
redirectUrl.searchParams.set("callbackUrl", callbackUrl.toString()); | |
localStorage.setItem("intended-url", window.location.href); | |
window.location.href = redirectUrl.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment