Last active
May 11, 2023 03:23
-
-
Save JLarky/7467999b9e025ec6b79c68e677f36082 to your computer and use it in GitHub Desktop.
Clerk redirect request https://twitter.com/JLarky/status/1656492372988153858
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
</head> | |
<body> | |
<script> | |
window.startClerk = async () => { | |
function formRedirect(){ | |
const form = '<form method="get" action="" name="redirect"></form>'; | |
document.body.innerHTML = document.body.innerHTML + form; | |
const searchParams = new URLSearchParams(window.location.search); | |
for (let paramTuple of searchParams) { | |
const input = document.createElement('input'); | |
input.type = 'hidden'; | |
input.name = paramTuple[0]; | |
input.value = paramTuple[1]; | |
document.forms.redirect.appendChild(input); | |
} | |
const url = new URL(window.location.origin + window.location.pathname + window.location.hash); | |
window.history.pushState({}, '', url); | |
document.forms.redirect.action = window.location.pathname + window.location.hash; | |
document.forms.redirect.submit(); | |
} | |
const Clerk = window.Clerk; | |
try { | |
await Clerk.load({ | |
isSatellite: false , | |
signInUrl: "", | |
}); | |
if(Clerk.loaded){ | |
if(window.location.href.indexOf('#') === -1){ | |
window.location.href = window.location.href; | |
} else if (window.navigator.userAgent.toLowerCase().includes('firefox/')){ | |
formRedirect(); | |
} else { | |
window.location.reload(); | |
} | |
} | |
} catch (err) { | |
console.error('Clerk: ', err); | |
} | |
}; | |
(() => { | |
const script = document.createElement('script'); | |
script.setAttribute('data-clerk-publishable-key', 'pk_live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); | |
script.async = true; | |
script.src = "https://clerk.mydomain.com/npm/@clerk/clerk-js@latest/dist/clerk.browser.js"; | |
script.crossOrigin = 'anonymous'; | |
script.addEventListener('load', startClerk); | |
document.body.appendChild(script); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment