Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to I get the shop id without having to do a query or api request ? #846

Open
thangpqgm opened this issue Sep 17, 2024 · 5 comments
Open

Comments

@thangpqgm
Copy link

Currently, I can get the shop domain in the session but I can't get the shop id.

I have to do a query into the session table to get the shop id, which is really annoying,

  const { session } = await authenticate.admin(request);
  const shopData = await db.shop.findFirst({
    where: { myshopifyDomain: session.shop },
  });
 console.log(shopData.shopifyShopId)

Getting the shop ID by calling rest API or graph ql also has the same cost.

I thought about saving the shop ID in a cookie but it seems impossible because the admin app is wrapped in an iframe tag,

So is there a simpler way for me to get the shop id in the loader?

@ccarlosm
Copy link

ccarlosm commented Sep 17, 2024

You can get it from session:

const shopDomain = session.shop;

Edit: I did not read well, the "id" is not possible to get without query, there are other disscusions about the topic

@matteodepalo
Copy link
Contributor

Hi @thangpqgm, thank you for opening this issue. I'm going to put it in front of the team for discussion.

@fairjm
Copy link

fairjm commented Nov 29, 2024

I want to know if it's safe to use this "shop" field as a store identifier, for scenarios like storing whether a shop is VIP or how many credits it has. Otherwise, wouldn't we need to retrieve a shopId again in each loader?

@byrichardpowell
Copy link
Contributor

byrichardpowell commented Dec 5, 2024

Hey everyone 👋

We chatted about this issue as a team but it was not clear to use exactly what the use case is. We understand you want the ID of the shop, but why? If you can frame the requirement in terms of a user flow or a business casse that would really help us decided how to address this.

@vincaslt
Copy link

vincaslt commented Dec 19, 2024

Judging by the recently released subscriptions reference app, it seems like it's safe to use session.shop as the identifier in your DB (i.e. tenant id): https://github.com/Shopify/subscriptions-reference-app/blob/main/prisma/schema.prisma

The prisma schema contains shop and is queried simply by always including shop from session.shop:

const dunningTracker = await prisma.dunningTracker.findFirst({
      where: {
        shop,
        contractId: subscriptionContract.id,
        billingCycleIndex,
      },
    });

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

No branches or pull requests

6 participants