How to get the right shop in app

How to get the right shop in app

anuragr
Shopify Partner
1 0 0
I have an app in which I have to get shop data and display relevant stuff on the front end. I get the correct shop by getting the current url and looking up from using that.
 
const shop = request.headers.get('origin').split("//")[1]
const session = await prisma.sessions.findMany({
  where: {
    shop: shop
  }
})
 
While this works in most cases, it breaks if the store owner changes domain post installation as I cant find the session anymore. Is there a better and more breakage free way to handle this situation?
 
 
Replies 0 (0)