Development discussions around Shopify APIs
To continue receiving payouts, you need to secure your account by turning on two-step authentication. If two-step authentication is not turned on your payouts will be paused. Learn more
Hello community!
I am trying to deploy Node Shopify Public App on different domains for Frontend and Backend.
Each time I call https://<MY_BACKEND_PATH>/auth?shop=<MY_SHOP> I get HTTP 302 with Location same as original request https://<MY_BACKEND_PATH>/auth?shop=<MY_SHOP>
I have NextJS run as static site on another domain. I have provided all correct Env variables to my Backend. I am using latest Shopify CLI. I have updated my Partner Dashboard correctly.
All is working fine with shopify node server i.e. with ngrok but fails in real life.
What have I missed?
Solved! Go to the solution
This is an accepted solution.
ok, seems having prefix in afterAuth is bad idea since it will not work for case when Koa deployed not on root /. Creating domain name and assigning it to my host's / solved the problem
ok, found issue... that's because I need to use prefix for Koa auth lib. Since I need to prepend each request with /dev/index I enforced to add
server.use(
createShopifyAuth({
prefix: "/dev/index",// I need this to have /dev/index/auth/inline redirect but not /auth/inline since it is not served by my Backend
async afterAuth(ctx) {
console.log("afterAuth", ctx);
// Access token and shop available in ctx.state.shopify
const { shop, accessToken, scope } = ctx.state.shopify;
const host = ctx.query.host;
ACTIVE_SHOPIFY_SHOPS[shop] = scope;
const response = await Shopify.Webhooks.Registry.register({
shop,
accessToken,
path: "/webhooks",
topic: "APP_UNINSTALLED",
webhookHandler: async (topic, shop, body) =>
delete ACTIVE_SHOPIFY_SHOPS[shop],
});
if (!response.success) {
console.log(
`Failed to register APP_UNINSTALLED webhook: ${response.result}`
);
}
// Redirect to app with shop parameter upon auth
ctx.redirect(`${process.env.BACKEND_URL}/?shop=${shop}&host=${host}`);
},
})
);
This is an accepted solution.
ok, seems having prefix in afterAuth is bad idea since it will not work for case when Koa deployed not on root /. Creating domain name and assigning it to my host's / solved the problem
User | RANK |
---|---|
6 | |
5 | |
5 | |
5 | |
4 |
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022