Redirect Login User to Previous Page (New customer accounts)

Redirect Login User to Previous Page (New customer accounts)

stats_marketing
Shopify Partner
26 3 15

Is there a way to redirect users when they log in to the previous page they were on before they landed on the log in page?

stats_marketing_1-1683831035288.png

 

We are using the New customer accounts:

 

stats_marketing_0-1683830975570.png

 

Replies 20 (20)

Bhaskar_Sonowal
Shopify Partner
21 5 4

1. Online Store > Themes.
2. Actions > Edit code.
3. In the Templates directory, click customers/login.liquid or the file that contains the login code.
4. Search for this line "{% form 'customer_login' %} "
5. Below it, Paste this :

 <input type="hidden" name="checkout_url" value="/collections/all">  

Replace the value in the above line with the page you want to display after login.

 

stats_marketing
Shopify Partner
26 3 15

@Bhaskar_Sonowal 

There is no `login.liquid` or anything close to that.  

This is not a theme thing.

 

The url when one clicks "account" goes to "/account" and then redirects to this:
`https://customer.login.shopify.com/lookup?destination_uuid=1234&redirect_uri=https%3A%2F%2Fshopify.c...`

I am thinking I can try to hard-code the "account" url in the Header and adding the parameter `redirect_uri`.


linia
Excursionist
29 2 31

I'm looking for this solution as well and cannot find the template mentioned in the theme either.  I'm trying to find the right form in main-login.liquid, but am not sure if I'm looking at the right page and if the new vs. old account are even in the same place.

 

Did you end up finding a solution and if so, would you be willing to share it with this thread?


Thanks for any help!

pgsean
Visitor
1 0 4

Just bumping this, I am also look for a solution where I can control the redirect on the New Account -> Login screen. 

We use YOTPO Loyalty and this New Account experience is extremely disruptive and confusing for customers since we can't include any of our Reward information or language on the New Account page. 

matoow
Shopify Partner
15 1 9

Any solution for this please?

 

MadsN
Shopify Partner
9 0 4

I had confirmed by Shopify Support that redirecting back to the original page with NEW customer accounts is *not* supported. They duggested reverting back to classic. 

Blipblopbloup
Shopify Partner
1 0 0

Is it still the case?

scottn
Shopify Partner
10 0 7

Yes unfortunately I confirmed this a few days ago with support.

linia
Excursionist
29 2 31

I reverted to using old accounts because of this - that's the only solution/workaround at the moment.

scottn
Shopify Partner
10 0 7

Yeah makes sense. We're using classic on our retail site, but our wholesale site uses Shopify's b2b features which unfortunately require new customer accounts. Kinda stuck in a bad spot here at the moment. Please help Shopify

frede-1994
Shopify Partner
12 0 5

Same boat here, need the b2b features but want to redirect to the front page after logging in.

Shopify please do something...

shahidameen
Shopify Partner
5 0 2

I have created this solution for New Customer Accounts

Basically I am getting Last URL of non-login customers in browser session storage, and when they login with new Customer Account, after login the users initially redirected to Order Status Page, but from there when they click on Store the Home Page opens with accountnumber query Parameter,

shahidameen_0-1734037777699.png

so based on that I have created a following logic, and it redirect customers back to the paqe where they get to the login page

{% unless customer %}
 <script>      
  sessionStorage.setItem("last_url_visited", "{{ canonical_url }}");
  if( sessionStorage.getItem("new_account_login") != null ){        
    sessionStorage.removeItem("new_account_login");      
  }  
 </script>
{% endunless %}
<script>
  const searchParams = new URLSearchParams(window.location.search);
  const cxAccNum = Number(searchParams.get('accountnumber'))
  if(cxAccNum >= 1 ){  
   if( sessionStorage.getItem("new_account_login") == null ){
     sessionStorage.setItem("new_account_login", "1");
     window.location = sessionStorage.getItem("last_url_visited")
   }
  }
</script>

,  

I Speak Liquid, JavaScript, GraphQL (and of course HTML, CSS)
frede-1994
Shopify Partner
12 0 5

Hey Shahidameen!

As far as I can understand, with your code the user is still directed to the account page after login, but then when going to the store he/she is redirected to the original page the came from before logging in - right?

 

My problem is I want the user to go straight to the front page of the store after login, so they don't ever see the account page unless they actively choose to go there. I don't think it is possible to add your script to the account page, which would be a way to solve this issue.

Not_guest_user
Shopify Partner
5 0 2

Not_guest_user_0-1734091187573.png

Try this and in retrun_to add your encoded return path

frede-1994
Shopify Partner
12 0 5

I am not sure what you mean, where should I create and use this URL?

Not_guest_user
Shopify Partner
5 0 2

you can replace the login URL with this (/customer_identity/login?return_to=) URL it will return the user after login to the given path

frede-1994
Shopify Partner
12 0 5

Where can you modify the login URL when using the new Customer Accounts?

shahidameen
Shopify Partner
5 0 2

Hello @frede-1994 

Now with Shopify Recent Release, you can just do that (Can be redirected back to the Previous Page from where login was originated) or to any custom page using 

storefront_login_url route in the routes object.


Here is Change Log.

https://changelog.shopify.com/posts/direct-customers-back-to-the-online-store-after-login

I Speak Liquid, JavaScript, GraphQL (and of course HTML, CSS)

shahidameen
Shopify Partner
5 0 2

With Recent Shopify Release, you can just do that, either redirect them to Previous Page where login was originated and even to the Custom Page. 

shahidameen_0-1734668365105.png


Here is the Change Log
https://changelog.shopify.com/posts/direct-customers-back-to-the-online-store-after-login


Credits: @Taylor Page

I Speak Liquid, JavaScript, GraphQL (and of course HTML, CSS)
frede-1994
Shopify Partner
12 0 5

Thanks a lot 🙂