Skip to content

Introduce new public auth mode for single shop tenant#873

Closed
alanko0511 wants to merge 1 commit into
mainfrom
alan/public-shop-tenant-auth-mode
Closed

Introduce new public auth mode for single shop tenant#873
alanko0511 wants to merge 1 commit into
mainfrom
alan/public-shop-tenant-auth-mode

Conversation

@alanko0511

@alanko0511 alanko0511 commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

This PR introduces a new authentication mode, publicShopTenant, that allows apps like Shopify theme app extensions to set up an unauthenticated role with a Shopify tenancy.

This allows use cases like fetching publicly accessible data for the specific shop without manually passing in the shop ID.

Click here to see an example usage

Example usage:

<!-- In extensions/theme-extension/blocks/star_rating.liquid -->
<script src="https://shop-auth-mode--development.ggt.pub/api/client/web.min.js" defer="defer"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
  window.gadgetPublicClient = new Gadget({
    authenticationMode: {
      publicShopTenant: {
        shopId: {{ shop.id }},
      },
    },
  });
})
</script>
<script src="{{ 'getShopInfo.js' | asset_url }}" defer="defer"></script>
// In extensions/theme-extension/assets/getShopInfo.js
const fetchCurrentShop = async () => {
  const shopInfoComponent = document.getElementById("shop-info");
  const shopInfo = await window.gadgetPublicClient.getCurrentShop();
  if (shopInfoComponent) {
    shopInfoComponent.innerHTML = JSON.stringify(shopInfo, null, 2);
  }
};

document.addEventListener("DOMContentLoaded", function() {
  fetchCurrentShop();
});

Then the shopInfoComponent should render the payload from the getCurrentShop global action.

PR Checklist

  • Important or complicated code is tested
  • Any user facing changes are documented (changelog section below)
  • Any app Problems are added to the problem finders
  • Any app data that needs a redeploy to take effect is listed in the contentHash functions
  • Important or complicated production behaviour has traces and logs added

Changelog

If this PR will affect change user-facing behaviour, add detailed information about the change here to prompt an AI generated changelog entry.

If no changelog is required, write no-changelog-required in square brackets [].

@alanko0511 alanko0511 force-pushed the alan/public-shop-tenant-auth-mode branch from fe08996 to 9711b82 Compare July 7, 2025 21:13
@alanko0511 alanko0511 force-pushed the alan/public-shop-tenant-auth-mode branch from 9711b82 to c18577b Compare July 8, 2025 17:34
@alanko0511 alanko0511 marked this pull request as ready for review July 8, 2025 17:52
InternalAuthToken = "internal-auth-token",
Anonymous = "anonymous",
Custom = "custom",
PublicShopTenant = "public-shop-tenant",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make sure we agree on best name for this

@alanko0511 alanko0511 marked this pull request as draft July 8, 2025 20:13
@alanko0511 alanko0511 closed this Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants