如何编辑NextJs服务器端代码以获得shopify授权?

我的代码遇到问题。我已经使用create-next-app创建了我的应用程序。我已经在Heroku上部署了我的应用程序,并且在shopify合作伙伴帐户应用程序中将URL列出了白色。现在,我可以使用URL https://YOUR_ADDRESS.io/auth?shop=YOUR_SHOPIFY_STORE.myshopify.com将其安装在shopify商店中。该应用程序已安装,并且可以按照以下步骤进行操作。但是我需要的是,当有人点击我的网站的网址时,它需要打开一个UI要求用户输入商店,单击“安装应用程序”按钮时,它会到达上面的URL并显示用户将其安装在shopify帐户。 这是我的代码

Server.js

require('isomorphic-fetch');
const dotenv = require('dotenv');
const Koa = require('koa');
const next = require('next');
const { default: createShopifyAuth } = require('@shopify/koa-shopify-auth');
const { verifyRequest } = require('@shopify/koa-shopify-auth');
const session = require('koa-session');

dotenv.config();

const port = parseInt(process.env.PORT,10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

const { SHOPIFY_API_SECRET_KEY,SHOPIFY_API_KEY } = process.env;

app.prepare().then(() => {
  const server = new Koa();
  server.use(session(server));
  server.keys = [SHOPIFY_API_SECRET_KEY];

  server.use(
    createShopifyAuth({
      apiKey: SHOPIFY_API_KEY,secret: SHOPIFY_API_SECRET_KEY,scopes: ['read_products'],afterauth(ctx) {
        const { shop,accessToken } = ctx.session;

        ctx.redirect('/');
      },}),);

  server.use(verifyRequest());
  server.use(async (ctx) => {
    await handle(ctx.req,ctx.res);
    ctx.respond = false;
    ctx.res.statusCode = 200;
    return
  });

  server.listen(port,() => {
    console.log(`> Ready on http://localhost:${port}`);
  });
});
huazai19851108 回答:如何编辑NextJs服务器端代码以获得shopify授权?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3103112.html

大家都在问