Members Only Page for logged in customers only

Topic summary

A user needed to restrict a specific page (“page.bart-s-army.json”) to logged-in customers only, with automatic redirect to login for non-authenticated users.

Initial Problem:

  • Implemented redirect logic in theme.liquid using checkout_url parameter
  • After login, users were redirected to account/orders page instead of the original restricted page
  • The redirect loop prevented access to the intended content

Solution Provided:

  • The checkout_url parameter doesn’t automatically redirect users after Shopify login
  • Fixed by storing the original URL in a query parameter and handling post-login redirection properly
  • Modified code provided to correctly capture and redirect to the intended page

New Issue:

  • The login redirect now prevents editing the page in Shopify’s theme editor
  • Editor URL triggers login redirect and breaks the editing interface
  • User seeking way to bypass redirect when accessing through theme editor (logging in within editor doesn’t work)

Status: Original redirect issue resolved; new editor access problem remains open.

Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

I have a page that I would like restricted to only show when customers are logged in. I want to redirect customers to login if they aren’t logged in. Currently I have tried this code and what is happening is when the customer logs in and goes back to view the page, it opens customers account/orders page and not the original page that is locked. It seems to continuously redirect to customer accounts instead of opening the page. (The page is named “page.bart-s-army.json”)

This code is in the theme.liquid file.

<html lang="{{ shop.locale }}">
  
  {% if template contains "army" %}
    {% unless customer %}
        {% assign send_to_login = true %}
    {% endunless %} 
  {% endif %}
  
  {% if send_to_login and request.path != "/challenge" %}
    <meta content="0; url=/account/login?checkout_url={{ request.path }}" http-equiv="refresh" />
  {% else %}

  <head>
    
    <!-- the <head> section of the file should go here -->

  </head>

  <body>

    <!-- the <body> section of the file should go here -->

  </body>

  {% endif %}

Hi @skyeabd ,

You’re on the right track, but the issue comes from the way Shopify handles redirects after login. The checkout_url parameter in account/login?checkout_url={{ request.path }} doesn’t automatically redirect users to the intended page after login. Instead, Shopify defaults to the customer account page.

Fix: Store the Intended Page Before Redirecting

You need to store the original URL in a query parameter and then handle redirection after login.

Fixed Code

Modify your theme.liquid file:


  {% if template contains "army" %}
    {% unless customer %}
        
    {% endunless %}
  {% endif %}

  
    
  

  
    
  

1 Like

Thank you so much for the help, I was struggling with what was going wrong for so long and this helped immensely. I am also wondering if there’s a way to exclude the login redirect when I am wanting to edit the page as I am running into the issue of not being able to edit in Shopify theme editor as the url tries to direct me to login and then breaks as its in theme editor. Is there a way to allow me access when editing the store page? I have tried logging in inside the editor but it does not work.