In this tutorial, we will see how to check if the customer is logged-in in Shopify app.
Shopify is a powerful CMS that allows us to easily create an e-commerce website. It also provides us an option to create custom apps that can be utilized to extend or add new features.
In case you are a newbie with Shopify app development and are just getting started one thing to remember is Shopify apps are server-side generated and use liquid templating.
Thus you can use the below code block to check if the customer is logged into the app or not.
{% if shop.customer_accounts_enabled %} {% if customer %} <a href="{{ routes.account_url }}">Account</a> {% else %} <a href="{{ routes.account_login_url }}">Login</a> {% if shop.customer_accounts_optional %} <span>or</span> <a href="{{ routes.account_register_url }}">Create an account</a> {% endif %} {% endif %} {% endif %}
You can learn more about the Shopify objects and liquid template cheat sheet.