app.prepare().then(() => {
server.use(
session(
{
sameSite: "none",
secure: true,
},
server
)
);
server.keys = [SHOPIFY_API_SECRET];
server.use(
createShopifyAuth({
apiKey: SHOPIFY_API_KEY,
secret: SHOPIFY_API_SECRET,
scopes: [SCOPES],
async afterAuth(ctx) {
// Access token and shop available in ctx.state.shopify
const { shop, accessToken } = ctx.state.shopify; //Store Access Token in Cookies
ctx.cookies.set("shopOrigin", shop, {
httpOnly: false,
secure: true,
sameSite: "none",
});
ctx.cookies.set("shopify_access_token", accessToken, {
httpOnly: true,
sameSite: "none",
secure: true,
}); // Redirect to app with shop parameter upon auth
server.context.client = await handlers.createClient(shop, accessToken);
await handlers.getSubscriptionUrl(ctx);
},
})
);
server.use(
graphQLProxy({
version: ApiVersion.October19,
})
);
router.get("(.*)", verifyRequest(), async (ctx) => {
await handle(ctx.req, ctx.res);
ctx.respond = false;
ctx.res.statusCode = 200;
});
server.use(router.allowedMethods());
server.use(router.routes());
server.listen(port, () => {
});
});