Skip to content

Instantly share code, notes, and snippets.

@JLarky
Last active May 11, 2023 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JLarky/7467999b9e025ec6b79c68e677f36082 to your computer and use it in GitHub Desktop.
Save JLarky/7467999b9e025ec6b79c68e677f36082 to your computer and use it in GitHub Desktop.
<!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