Customer is logged into the shopify store or not

Customer is logged into the shopify store or not

VishalChandola
Shopify Partner
11 0 0

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?

Replies 2 (2)

Dan-From-Ryviu
Shopify Partner
8547 1685 1692

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

 

- Helpful? Like and Accept solution to let me know or Buy me Coffee ❤️!
- Ryviu - Product Reviews app, collect product reviews, import reviews from AliExpress, Amazon, Etsy, Shopee and Walmart and CSV.
- Lookfy app: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Enjoy 1 month of Shopify for $1. Sign up now.

VishalChandola
Shopify Partner
11 0 0

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?"