如何使用SQLite设置和访问Shopify会话?



这是用SQLiteSessionStorage建立商店的正确方法吗?

const storage = new SQLiteSessionStorage(DB_PATH)
const shopify = shopifyApp({
api: {
apiVersion: LATEST_API_VERSION,
restResources,
billing: undefined, // or replace with billingConfig above to enable example billing
scopes: ['write_products', 'read_locales'],
},
auth: {
path: '/api/auth',
callbackPath: '/api/auth/callback',
},
webhooks: {
path: '/api/webhooks',
},
sessionStorage: storage,
});
export default shopify;

如果是这样,我怎么能从我的应用程序的任何地方访问这个会话?

这样的:

shopify.js(假设您使用shopifyApp和SQLite作为db):

import { shopifyApp } from "@shopify/shopify-app-express";
import { SQLiteSessionStorage } from "@shopify/shopify-app-session-storage-sqlite";
const dbFile = join(process.cwd(), "database.sqlite");
const sessionDb = new SQLiteSessionStorage(dbFile);
const shopify = shopifyApp({
[...]
sessionStorage: sessionDb,
});

文件夹/your.function.js:

import shopify from "../shopify.js";
const sessionId = await shopify.api.session.getOfflineId('myshop.shopify.com');
const session = await shopify.config.sessionStorage.loadSession(sessionId);
const restClient = new shopify.api.clients.Rest({ session });

相关内容

  • 没有找到相关文章

最新更新