I want to redirect non-logged-in users to login, signup page.

In my website I want to build a functionality that if a non logged in user enters the website it will redirected to the login or register page and if a logged in user enters the website they can redirect to website landing page.

Hi @Surbhi_Dudhe , I’ve tried this previously adding in the theme.liquid file but it issues in continuous reloading. I’ve find a solution and the issue is resolved.

This is the code I’ve added

{% if customer %}

{% else %}

{% endif %}

1 Like

This works great, but how can we make it so that they are allowed to visit the create account page?

This solution will allow your customers/visitors to visit both the login page and the registration page, simply paste it into your theme.liquid file above .

{% comment %}
Shopify Liquid Authentication Redirect by CCC Digital

This code:

  1. Checks if the customer is logged in
  2. If not logged in, redirects to login page
  3. Allows access to login and registration pages without redirection
    {% endcomment %}

{% unless customer %}
{% assign current_url = request.path %}
{% unless current_url contains ‘/account/login’ or current_url contains ‘/account/register’ %}

{% endunless %}
{% endunless %}