Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Restrict page to logged-in users only

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
617 59 145

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.

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ

View solution in original post

PaulMartin
Shopify Partner
617 59 145

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 %}

 

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ

View solution in original post

Replies 10 (10)

PaulMartin
Shopify Partner
617 59 145

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.

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ
PaulMartin
Shopify Partner
617 59 145

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 %}

 

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ
AskTryTry
Tourist
4 0 2

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

PaulMartin
Shopify Partner
617 59 145

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

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ
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
617 59 145

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.

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ
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
617 59 145

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

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ

PurplePartner
Shopify Partner
193 18 34

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
617 59 145

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.

contact@paulmartinlopez.com
Feel free to email me! 😄
I'm open to conversations or work ʕ •ᴥ•ʔ