Shopify Storage Redis与Node React应用程序的问题



我在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文件中添加了附加在文件中的代码,但当我运行安装应用程序时,它会多次进入storeCallback、loadcallback和deletecallback函数

StoreCallback函数代码

加载和删除回调函数代码

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

最新更新