Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I am writing an app, and I want the app to have an "admin" mode that detects when the Shop Owner, or if possible registered users designated by the Shop owner, are logged into the store. When the app recognizes an "admin" is logged into the store, we will use this to show admin controls.
I'm also looking for guidance on this as well.
There is a User resource in the API, which has an attribute that indicates if the User is the store owner. However, the documentation says:
The User resource is available forprivate appsandcustom appsinstalled onShopify Plusstores. Contact Shopify Plus Support to enable this API resource for your store.
https://shopify.dev/api/admin-rest/2022-01/resources/user#top
I'm not sure if that means it's ONLY available for those apps, which seems strange given priority of Public apps.
That said, I'm also trying to adjust our UX if the user is store admin, so any guidance from Shopify would be helpful.
You can use content_for_header details to detect admin and more inside liquid.
The following example snippet will only load the app proxy script if the visitor is not:
(1) An Admin or Staff User
(2) Shopify Theme Designer
{% capture CFH %}{{ content_for_header }}{% endcapture %}
{% if CFH contains 'adminBar' or CFH contains 'designMode' %}
{% else %}
<script src="https://{{ request.host }}/apps/app-proxy-url"></script>
{% endif %}
All other visitors will trigger the app proxy.
It does this by capturing the content_for_header value and checking for the presence of code that Shopify only ever adds when an admin or staff member is logged in, or code that is appended by the theme designer.
If this code is present the result is an empty string, but if this code is not present (i.e. it's a normal visitor) the code will run and the app proxy script tag will get injected.
Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024