Shopify / shopify-app-template-remix

337 stars 143 forks source link

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

Open thangpqgm opened 2 weeks ago

thangpqgm commented 2 weeks ago

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 commented 2 weeks ago

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 commented 1 week ago

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