Solved

Restrict page to logged-in users only

AskTryTry
Tourist
4 0 2

Hi all, 

 

I am trying to limit this page to only my logged-in users, non logged-in users should be prompted to sign up for an account. 

 

Is there way to do so?

 

 

Link: https://trytrysg.myshopify.com/pages/share-review

 

 

Screenshot 2024-02-22 at 5.12.50 PM.png

Accepted Solutions (2)
PaulMartin
Shopify Partner
193 34 63

This is an accepted solution.

You can also avoid using a third-party app and just write a few lines of code to either hide the section or redirect the user.

View solution in original post

PaulMartin
Shopify Partner
193 34 63

This is an accepted solution.

Here's a test of it: redirect when not logged in – practice-agood
password: 1

Here's the script

{% if customer == nil %}
  <h1>Redirecting, See you!</h1>
  <script>
    addEventListener("load", (event) => {
      let redirect_path = "https://www.google.com";
      window.location.replace(redirect_path);
    });
  </script>
{% endif %}

 

View solution in original post

Replies 10 (10)

PaulMartin
Shopify Partner
193 34 63

Hmmm. Shopify has a way to add redirects, but it looks like it redirects everyone. Shopify Help Center | URL redirects

Normally this should be done in the backend, but you can write a script that will redirect the user if they are not logged in with Liquid and JS.

PaulMartin
Shopify Partner
193 34 63

This is an accepted solution.

Here's a test of it: redirect when not logged in – practice-agood
password: 1

Here's the script

{% if customer == nil %}
  <h1>Redirecting, See you!</h1>
  <script>
    addEventListener("load", (event) => {
      let redirect_path = "https://www.google.com";
      window.location.replace(redirect_path);
    });
  </script>
{% endif %}

 

AskTryTry
Tourist
4 0 2

Hi, thanks for the reply. I will message you.

PaulMartin
Shopify Partner
193 34 63

Cool. Just do so and I'll reply when I'm available.

AskTryTry
Tourist
4 0 2

Sorry, can't seem to find a way to message you directly. Can I know where can I add your code to my page? 

PaulMartin
Shopify Partner
193 34 63

Click on my profile and you should see send a message button. Unfortunately, I need to look at your theme first before deciding where to add the code.

AskTryTry
Tourist
4 0 2

Doesn't seem to have the option, can I get your email? Or could you email me at asktrytry@gmail.com please? Thank you! 

PaulMartin
Shopify Partner
193 34 63

Sent you an email. You can now remove your email in your message by editing it.

PurplePartner
Shopify Partner
178 18 30

Hi @AskTryTry,

 

You can use a third-party app to hide the section from all visitors excluding the logged-in users. This will solve your issue with ease and prevent any frustrations or issues in the future. 

 

Locksmith has been one of the most used apps for this. Give it a shot. Alternatively, you can look for other apps here

 

Have a nice one!

Did you find my response useful? Mark it as "Accepted solution" so others can see it, or just like it.
PaulMartin
Shopify Partner
193 34 63

This is an accepted solution.

You can also avoid using a third-party app and just write a few lines of code to either hide the section or redirect the user.