nextjs-shopify-auth
nextjs-shopify-auth copied to clipboard
Add support for `host` parameter used by Shopify App Bridge 2.0
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
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();
},