How can I create viewable pages for logged-in staff only?

How can I create viewable pages for logged-in staff only?

jacobgraf
Shopify Partner
13 0 12

I need to create a few pages that are viewable by logged-in staff only. If someone else tries to load these pages, it should just redirect to the homepage. Has anyone found a way to accomplish this? It's a shame there is no native liquid magic to do something like this. e.g. {% if staff.logged_in %} or similar.

Replies 2 (2)

Uhrick
Shopify Partner
433 68 102

hey, Jacobgraf.

Adding a tag 'Staff' to the staff accounts and then doing the validation using that wouldn't work?

Shopify Developer
Hire me for theme customizations at ricardomsilvestre@outlook.com or Upwork
Was my answer helpful to you? Please like or mark as solution

gina-gregory
Shopify Partner
742 51 213

 

I've seen some do this... make your pages have a 'staff-only' template, check the content_for_header object for 'adminBarInjector' which only is included if you're visiting the site in the same browser you are also logged into the admin in.

{% if template.suffix == 'staff-only' %}
{% if content_for_header contains 'adminBarInjector' %}
  ... staff only content
{% else %}
  <script>window.location.href = '/';</script>
{% endif %}
{% endif %}