New Shopify Certification now available: Liquid Storefronts for Theme Developers

Redirect after Shopify Logout

anthonythomas
Shopify Partner
6 0 0

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.
Replies 3 (3)
parmindersidhu
Shopify Partner
3 0 0

you can use this in theme.liquid before end the body tag
<script>
$(document).ready( function() {
$('a[href^="/account/logout"]').on("click", function() {
$.ajax( $(this).attr('href') )
.done(function() {
window.location.href = "/cart";
});
return false;
});
});
</script>

bds89
Visitor
3 0 0

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?

Volodymyr_Pekur
Visitor
1 0 0

I used the following method
<a href="/account/logout?return_url=%2Faccount" >Logout</a>