Skip to content

Instantly share code, notes, and snippets.

@pablof7z
Created March 13, 2024 11:37
Show Gist options
  • Save pablof7z/20911e5caa0c61f970f45fec1172e0c1 to your computer and use it in GitHub Desktop.
Save pablof7z/20911e5caa0c61f970f45fec1172e0c1 to your computer and use it in GitHub Desktop.
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