Skip to content

Instantly share code, notes, and snippets.

@herveguetin
Created November 4, 2025 21:00
Show Gist options
  • Select an option

  • Save herveguetin/1bf585574dd9381d209ec2287fb75c63 to your computer and use it in GitHub Desktop.

Select an option

Save herveguetin/1bf585574dd9381d209ec2287fb75c63 to your computer and use it in GitHub Desktop.
Shopify • Market-safe post-login redirect
const makeLoginRedirectUrl = (path = ""): string => {
const currentUrl = new URL(window.location.href);
const basePath = Shopify.routes.root.replace(/\/$/, "");
const returnPath = path || `${currentUrl.pathname}${currentUrl.search}`.replace(basePath, "");
const returnTo = `${basePath}/${returnPath}`.replace(/\/{2,}/g, "/");
return `${currentUrl.origin}/customer_authentication/login?return_to=${encodeURIComponent(returnTo)}`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment