为Shopify公共应用程序生成在线和离线访问令牌

为Shopify公共应用程序生成在线和离线访问令牌,shopify,koa,shopify-app,shopify-api,shopify-api-node,Shopify,Koa,Shopify App,Shopify Api,Shopify Api Node,Shopify的样板应用程序这样做是为了生成访问令牌(默认情况下为在线访问模式) 在我的情况下,我需要在线和离线令牌 离线令牌将生成一次(如果存储未添加到我的数据库中),accessMode设置为Offline并推送到DB 当前登录用户的联机令牌 有没有办法在一个流中生成两个令牌 下面这个不行。膝关节炎反应:404未发现 server.use(function (ctx, next) { console.log(JSON.stringify(ctx.request.query.sh

Shopify的样板应用程序这样做是为了生成访问令牌(默认情况下为在线访问模式)

在我的情况下,我需要在线和离线令牌

  • 离线令牌将生成一次(如果存储未添加到我的数据库中),accessMode设置为Offline并推送到DB
  • 当前登录用户的联机令牌
有没有办法在一个流中生成两个令牌

下面这个不行。膝关节炎反应:404未发现

server.use(function (ctx, next) {

    console.log(JSON.stringify(ctx.request.query.shop))
    if (ctx.request && ctx.request.query && ctx.request.query.shop) {
        if (isStoreAlreadyAdded(ctx.request.query.shop) === 0) {
            createShopifyAuth({
      apiKey: SHOPIFY_API_KEY,
      secret: SHOPIFY_API_SECRET,
      scopes: [SCOPES],
      accessMode: 'offline',

      async afterAuth(ctx) {
        // Access token and shop available in ctx.state.shopify
        const { shop } = ctx.state.shopify;

        // Redirect to app with shop parameter upon auth
        ctx.redirect(`/?shop=${shop}`);
      },
    })
        }
    } else {
        shopifyAuth({
            afterAuth(ctx) {
                const {shop, accessToken} = ctx.state.shopify;
                console.log('We did it!', accessToken);
                ctx.redirect(`/?shop=${shop}`);
            },
        })
    }
});

你知道怎么让它工作了吗?对于其他人来说,github中的这个问题可以帮助您:
server.use(function (ctx, next) {

    console.log(JSON.stringify(ctx.request.query.shop))
    if (ctx.request && ctx.request.query && ctx.request.query.shop) {
        if (isStoreAlreadyAdded(ctx.request.query.shop) === 0) {
            createShopifyAuth({
      apiKey: SHOPIFY_API_KEY,
      secret: SHOPIFY_API_SECRET,
      scopes: [SCOPES],
      accessMode: 'offline',

      async afterAuth(ctx) {
        // Access token and shop available in ctx.state.shopify
        const { shop } = ctx.state.shopify;

        // Redirect to app with shop parameter upon auth
        ctx.redirect(`/?shop=${shop}`);
      },
    })
        }
    } else {
        shopifyAuth({
            afterAuth(ctx) {
                const {shop, accessToken} = ctx.state.shopify;
                console.log('We did it!', accessToken);
                ctx.redirect(`/?shop=${shop}`);
            },
        })
    }
});