You will probably need to change your HOST variable in your .env file at the root of your project.
If we look inside the koa-shopify-auth package, we can see the following:
export default function createOAuthStart(
options: OAuthStartOptions,
callbackPath: string,
) {
return function oAuthStart(ctx: Context) {
const {myShopifyDomain} = options;
const {query} = ctx;
const {shop} = query;
const shopRegex = new RegExp(
`^[a-z0-9][a-z0-9\\-]*[a-z0-9]\\.${myShopifyDomain}$`,
'i',
);
if (shop == null || !shopRegex.test(shop)) {
ctx.throw(400, Error.ShopParamMissing);
return;
}
ctx.cookies.set(TOP_LEVEL_OAUTH_COOKIE_NAME, '', getCookieOptions(ctx));
const formattedQueryString = oAuthQueryString(ctx, options, callbackPath);
ctx.redirect(
`https://${shop}/admin/oauth/authorize?${formattedQueryString}`,
);
};
}
The redirect is being created in the oAuthQueryString module. If we take a look in that module, the redirect_uri is being created with your process.env.HOST variable, which is being propagated through the Koa context.
export default function oAuthQueryString(
ctx: Context,
options: OAuthStartOptions,
callbackPath: string,
) {
const {host, cookies} = ctx;
const {scopes = [], apiKey, accessMode} = options;
const requestNonce = createNonce();
cookies.set('shopifyNonce', requestNonce, getCookieOptions(ctx));
/* eslint-disable @typescript-eslint/camelcase */
const redirectParams = {
state: requestNonce,
scope: scopes.join(', '),
client_id: apiKey,
redirect_uri: `https://${host}${callbackPath}`,
};
/* eslint-enable @typescript-eslint/camelcase */
if (accessMode === 'online') {
redirectParams['grant_options[]'] = 'per-user';
}
return querystring.stringify(redirectParams);
}
This is fine to have set as https://localhost:3000 when you’re in dev mode, but in production, you’ll need to change the environment variable in the production environment. I haven’t used IIS in a long time, but I’m sure there’s a way to set your HOST var to your production domain.
In Heroku, for example, you can set it within the web app for the deployment, or on the CLI.
Here’s a screenshot of a production embedded app’s config vars in Heroku:
Hope that helps!