How can I redirect to a custom domain after logging out of a Shopify account?

Topic summary

Main issue: After calling /account/logout, Shopify redirects users back to the myshopify.com domain. The goal is to redirect to an external custom domain (e.g., example.vercel.app) in a headless setup.

Workarounds discussed:

  • JavaScript in theme.liquid intercepts clicks on /account/logout, sends an AJAX request to log out, then client-side redirects (example to /cart). This relies on theme scripts and jQuery; it won’t work where theme code isn’t loaded (e.g., checkout).
  • Using /account/logout?return_url=%2Faccount to redirect after logout to an internal, relative path. External redirects were not demonstrated or confirmed.

Additional asks:

  • Conditional redirects based on the specific logout link clicked; no concrete solution provided.
  • Logout button at checkout page: the JS approach doesn’t work there; no alternative offered.

Headless/security concern:

  • Request for an official way to programmatically log out customers and revoke their access tokens to match API-based login flows.

Status: Unresolved. No confirmed method to redirect to an external domain after logout; current options are limited to theme-based JS and possible internal return_url redirects. A platform-level solution is requested.

Summarized with AI on December 11. AI used: gpt-5.

Hello Shopify Community!

I’m implementing an authentication system on the headless side by controlling cookie data. I log in on the Shopify account page, and it redirects to our headless site, and it saves cookie data.
I made the logout link in the headless side, and its link is https://xxx.myshopify.com/account/logout. When I click this link, I removed cookie data, and redirects to this link, then it is logged out of Shopify store.
But after logout, it automatically redirects to https://xxx.myshopify.com. I just want to redirect to the custom domain, like https://example.vercel.app. So it is an external link.

Are there any solution for this? Like the redirect after login. We can redirect to custom page after Shopify login using the following link. https://xxx.myshopify.com/account/login?return_url=%2Faccount. I want this kind of solution for logout or any other solutions.

Thank you in advance.

1 Like

you can use this in theme.liquid before end the body tag

I would like to redirect users to two different urls depending on the link selected. I’ve been trying to work out a way to pass a condition to your script, which others have shared, but can’t come up with a way to do it. Any ideas?

I used the following method
Logout

Hi Parmindersidhu ,

This code is not working for logout button at checkout page. Do you have any solution for that?

Adding my vote for this. It represents a significant functional gap for headless Shopify builds. The ability to programmatically log out a customer and revoke their access token is a fundamental requirement for achieving secure and complete customer authorization parity with the existing API-based login.