nextjs-shopify-auth icon indicating copy to clipboard operation
nextjs-shopify-auth copied to clipboard

Add support for `host` parameter used by Shopify App Bridge 2.0

Open jmurty opened this issue 2 years ago • 1 comments

Thanks for this awesome library! It has saved me a lot of time getting started with Shopify app development.

In case anyone is still working on this library...

The newer version 2 of Shopify App Bridge requires a new host parameter in the @shopify/app-bridge-react AppProvider config instead of the previous shopOrigin parameter. This host parameter isn't recognised or passed on by the authenticateShopifyPage() function.

Ideally this library would detect when the host parameter is present, store it in a cookie or browser storage, and provide in the result of authenticateShopifyPage() and it wherever else it's likely to be needed client-side. The parameter needs to be stored because it isn't available on every page load

For now I'm doing this ☝️ in my own app, but it would be nice to get it from the library.

See https://shopify.dev/apps/tools/app-bridge/migrating and https://shopify.dev/apps/tools/app-bridge/retrieve-the-host

jmurty avatar Feb 23 '22 06:02 jmurty

you can access it in afterAuth using req.query.host

  async afterAuth({
    shopOrigin,
    shopifyToken,
    shopifyAssociatedUser,
    req,
    res,
  }) {
    let redirectUrl = `/?host=${req.query.host}`;
    console.log(
      `We're authenticated on shop ${shopOrigin}: ${shopifyToken} with user ${JSON.stringify(
        shopifyAssociatedUser
      )}`
    );
    res.writeHead(302, { Location: redirectUrl });
    res.end();
  },

dottodot avatar Jan 10 '23 11:01 dottodot