I’m trying to make a collection page password protected in Shopify (liquid).
I’m trying to check if localstorage item "Password" is set with the right value.
If that’s the case include ‘snippet’.
Whats the best approach to do something like this?
This will break the js earlier cuz of the %}:
if (!localStorage.getItem("password")) {
{% include 'protected-collection-form' %}
} else {
{% include 'protected-collection' %}
}
2
Answers
You can’t access frontend JS in server-side liquid. Do this instead.
On the password submission store the password in cart’s attribute using a fetch.
and now you can use liquid like this:
Use the
customer
variable. Ifcustomer != nil
(nil
means the value isnull
), then user is not authenticated.