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
11558 2262 2447

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 & Accept solution!
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
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?"