I'm using react to write my app, which will be presented on my shopify store using app proxy. I have a link /customer-id that displays customer data. This link is created by the shopify theme and my app is able to access the customer id and show customer data. The problem is that anyone with this link can view the data. I know within liquid I can have an if else to check the logged in customer. But how can i achieve the same behaviour using react, and not liquid?
0
votes
1 Answers
1
votes
Send {{ customer.id }} as another variable to your server using AppProxy. this variable will give null value if customer is not logged in.
But this variable will render in liquid file only. so making App Proxy request using Script Tag won't work here.
You need to write this js ( in normal script tag ) in the liquid file like theme.liquid or in the page.liquid ( if you are using custom page ).
for this you can simply create snippet using API and append include code. ( or manually enter like below )
{% include 'app-proxy-initiator' %}
Now in the back end logic just send response if your custom variable is not null and match with the id in URL from where call has been made.
Hope this will help.