使用Node React应用程序时出现的Shop ify Storage Redis问题

whhtz7ly  于 2022-12-11  发布在  Redis
关注(0)|答案(1)|浏览(110)

我在serve.js中添加了会话存储,如下所示:

import SessionHandler from "./SessionHandler";
const sessionStorage = new SessionHandler();

Shopify.Context.initialize({
  API_KEY: process.env.SHOPIFY_API_KEY,
  API_SECRET_KEY: process.env.SHOPIFY_API_SECRET,
  SCOPES: process.env.SCOPES.split(","),
  HOST_NAME: process.env.HOST.replace(/https:\/\//, ""),
  API_VERSION: ApiVersion.October21,
  IS_EMBEDDED_APP: false,
  // This should be replaced with your preferred storage strategy
  //SESSION_STORAGE: new Shopify.Session.MemorySessionStorage(),
  SESSION_STORAGE: new Shopify.Session.CustomSessionStorage(
    sessionStorage.storeCallback,
    sessionStorage.loadCallback,
    sessionStorage.deleteCallback
  ),
});

我的路由器获取函数是

router.get("(.*)", async (ctx) => {
    const shop = ctx.query.shop;
    let documentQuery = { shop: shop };
    let data = await SessionStorage.findOne(documentQuery);   //this finds the store in the session table
    if (ACTIVE_SHOPIFY_SHOPS[shop] === undefined) {
      if (data == null) {
        ctx.redirect(`/auth?shop=${shop}`);
      } else {
        await handleRequest(ctx);
      }
    } else {
      await handleRequest(ctx);
    }
  });

然后在SessionHandler文件中添加了附加在文件中的代码,但是当我运行install应用程序时,它会多次转到storeCallback、loadcallback和deletecallback函数
StoreCallback Function Code
Load and delete callback function code

2ic8powd

2ic8powd1#

对不起,我修改了我的答案,因为我认为它是不正确的。现在我所能说的就是看看这个例子:https://github.com/Shopify/shopify-api-node/blob/main/docs/usage/customsessions.md如果您尚未..

相关问题