Customer is logged into the shopify store or not

I have created a discount app and the app is designed to apply discounts exclusively to logged-in customers. How can I determine if a customer is logged in on the store?

Hi @VishalChandola

You can use this code to check if the customer logged in

{% if customer %}

{% endif %}

You can check this to learn more about Shopify customer for dev

https://shopify.dev/docs/api/admin-rest/2023-10/resources/customer

Hi @Dan-From-Ryviu the implementation is now functioning correctly. I’ve added this code snippet in theme.liquid to determine if the customer is logged in or not:

{% if customer %}
localStorage.setItem('isLoggedIn', 'true');
{% else %}
localStorage.setItem('isLoggedIn', 'false');
{% endif %}

However, I’m encountering an issue in the Shopify discount app while trying to read from localStorage. The error displayed is: ‘Uncaught ReferenceError: ‘localStorage’ is not defined’. Any suggestions on how to resolve this?"