Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Shopify Koa missing HOST header

Shopify Koa missing HOST header

Katarina_Heady
Visitor
2 0 0

I am trying to generate an offline token with the shops using Shopify CLI for with Koa authentication module. 

 

Something like this: 

 

server.keys = [Shopify.Context.API_SECRET_KEY];
  server.use(
    createShopifyAuth({
      accessMode: "offline",
      async afterAuth(ctx) {
        // Access token and shop available in ctx.state.shopify
        const { shop, accessToken, scope } = ctx.state.shopify;
     })
  )

 

 

However, when I try to run this flow with newly created stores, I am getting an error from the Shopify App Bridge, that Host is required, and app fails to render. 

 

class MyApp extends App {
  render() {
    const { Component, pageProps, host, isValidStore } = this.props;

    return (
      <AppProvider i18n={translations}>
        <Provider
          config={{
            apiKey: API_KEY,
            host: host,
            forceRedirect: true,
          }}
        >
          <MyProvider
            isValidStore={isValidStore}
            Component={Component}
            {...pageProps}
          />
        </Provider>
      </AppProvider>
    );
  }
}

 

 

I am fetching this using following method: 

 

MyApp.getInitialProps = async ({ ctx }) => {
  return { host: ctx.query.host };
};

 

 

It is not able to get the host in the query parameter, probably because Shopify is not passing it. Is there something that I'm missing? 

 

PS: 

Package versions are as followed: 

 

"@shopify/app-bridge-react": "2.0.13",
"@shopify/app-bridge-utils": "2.0.13",
"@shopify/koa-shopify-auth": "5.0.3",
"@shopify/polaris": "9.0.0",

 

 

Thank you for the help in advance. 

Reply 1 (1)

SeanWilson
Shopify Staff (Retired)
3 2 2

Hi @Katarina_Heady. Thanks for reporting this. I'm a PM at Shopify. We've fixed this issue and the host parameter is now included.

To learn more visit the Shopify Help Center or the Community Blog.