Obtain the ShopID in the front end - Passing from Koa middleware

psmod2
Shopify Partner
11 1 0

Hi,

I'm developing an app where I need to store some data against the StoreID of where the app is installed.

However I'm not sure how this is done. I need it to be available to me on the front end - where I make a save request to my DB.

I'm using `koa-shopify-auth` and have seen its available there, however thats the middleware, so how do I pass the value to the front end?

I'm really unsure of the flow/logic of how this would work. Any help would be appreciated.

Here is the link that shows its available from `ctx`- but again I have no idea how I can use ctx in my front end JS pages:
https://shopify.dev/tutorials/get-and-store-the-shop-origin

Thanks.

0 Likes
psmod2
Shopify Partner
11 1 0

I've been looking around a little more, trying to understand and is this correct - I would pass the storeId from the Koa middleware to the front end with each request?

I'm able to save it as a cookie - however now I have 3 more questions:

- Is this the correct way to handle this?

- Won't it be set each request - is this ok?

- Reading the cookie seems troublesome now. The cookie is in the child frame (as the app sits in its own iframe).

Any help appreicated.

 

 

server.use(async (ctx) => {
   ctx.cookies.set("shopName", ctx.session.shop, {withCredentials: true, sameSite: 'none'})

   await handle(ctx.req, ctx.res);
   ctx.respond = false;
   ctx.res.statusCode = 200;
   return
});

 

 

 

0 Likes