Skip to content

Introduce shopId in browserSession to set shop tenant#875

Merged
alanko0511 merged 2 commits into
mainfrom
alan/unauth-shopify-tenant
Jul 15, 2025
Merged

Introduce shopId in browserSession to set shop tenant#875
alanko0511 merged 2 commits into
mainfrom
alan/unauth-shopify-tenant

Conversation

@alanko0511

@alanko0511 alanko0511 commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

This PR introduces a new property in browserSession, shopId, that allows apps like Shopify theme app extensions to set up a session with a Shopify tenancy.

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

This PR also allows setting authentication modes at the top level, i.e. no need to declare the modes under the authenticationMode.

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 () {
  const client = new Gadget({
    browserSession: {
      shopId: {{ shop.id }},
    },
  });

  client.getCurrentShop().then((result) => {
    const shopInfoElement = document.getElementById("shop-info");
    shopInfoElement.innerHTML = JSON.stringify(result, null, 2);
  })
})
</script>

<pre id="shop-info"></pre>

Then the shopInfoComponent should render the payload from the getCurrentShop global action with the current shop's data.

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/unauth-shopify-tenant branch 2 times, most recently from 20a29b8 to 4aaed11 Compare July 10, 2025 14:26
@alanko0511 alanko0511 marked this pull request as ready for review July 10, 2025 16:34

@infiton infiton left a comment

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.

looks good; mind adding some type tests to make sure we have type errors if more than one option is passed

@MillanWangGadget MillanWangGadget left a comment

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.

looks reasonable 👍

@alanko0511 alanko0511 force-pushed the alan/unauth-shopify-tenant branch 2 times, most recently from 9bda259 to 95c5c43 Compare July 14, 2025 14:16
@alanko0511 alanko0511 force-pushed the alan/unauth-shopify-tenant branch from 95c5c43 to df97dea Compare July 14, 2025 14:18
@alanko0511 alanko0511 force-pushed the alan/unauth-shopify-tenant branch from a8be7b3 to 37e3078 Compare July 15, 2025 14:22

@infiton infiton left a comment

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.

looks good I think you can ship this one first; you'll need to cut a new release

@alanko0511 alanko0511 merged commit 794127e into main Jul 15, 2025
10 checks passed
@alanko0511 alanko0511 deleted the alan/unauth-shopify-tenant branch July 15, 2025 14:41
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.

3 participants