ctx.cookies.set('shopOrigin') doesn't work

cedriclajato
New Member
3 1 1

Hello Guys,

I have followed this latest tutorial from shopify - https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react

On my server.js I have this code:

 

      afterAuth(ctx) {
        const { shop, accessToken } = ctx.session;
        ctx.cookies.set('shopOrigin', shop, {
          httpOnly: false,
          secure: true,
          sameSite: 'none'
        });
    }

 

 

On my _app.js I have this code:

 

const config = { apiKey: API_KEY, shopOrigin: Cookies.get("shopOrigin"), forceRedirect: true };

 

 

During installation I tried to console log the config

 

  const config = { apiKey: API_KEY, shopOrigin: Cookies.get("shopOrigin"), forceRedirect: true };
  console.log(config);

 

 

I got this response:

 

{
apiKey: '4967243417b61ca632f8111072003815',
shopOrigin: undefined,
forceRedirect: true
}

 

 

Looks like the ctx.cookies.set('shopOrigin') functionality doesn't work anymore.

Is anyone experience the same issue or do shopify has new way to do it now?

Thank you in advance.

 

Kind regards,
Cedric

davidhollenbeck
Shopify Partner
9 0 1

bump - same issue here. confirmed the auth is being generated via console log on the app but cookie isn't being set

0 Likes
davidhollenbeck
Shopify Partner
9 0 1

for the next person who finds this, i figured this out, just needed to add some more options to ctx.  I know sameSite is to deal with a chrome update, the other ones tbh not sure if they're necessary but it's working now so I'm keeping as is lol

ctx.cookies.set("accessToken", accessToken, {
httpOnly: true,
secure: true,
signed: true,
overwrite: true,
sameSite: 'none',
});
ctx.cookies.set("shopOrigin", shop, {
httpOnly: true,
secure: true,
signed: true,
overwrite: true,
sameSite: 'none',
});