首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shopify (Node + React)自定义应用程序: verifyRequest()问题

Shopify (Node + React)自定义应用程序: verifyRequest()问题
EN

Stack Overflow用户
提问于 2021-06-08 14:24:35
回答 1查看 385关注 0票数 0

我正在用Node+React开发一个定制的嵌入式应用程序。

我遵循了官方教程,但是如果我使用verifyRequest()中间件,在浏览应用程序的页面时总是会出现以下错误:

期望有一个有效的商店查询参数

我真的不明白密码出了什么问题。

有人能帮帮我吗?

下面是server.js代码

代码语言:javascript
复制
require('isomorphic-fetch');
const dotenv = require('dotenv');
const Koa = require('koa');
const next = require('next');
const { default: shopifyAuth } = require('@shopify/koa-shopify-auth');
const { verifyRequest } = require('@shopify/koa-shopify-auth');
const { default: Shopify, ApiVersion } = require('@shopify/shopify-api');
const Router = require('koa-router');
const RedisSessionStorage = require('./middleware/RedisSessionStorage')
const Cookies = require('cookies')

dotenv.config();

Shopify.Context.initialize({
    API_KEY: process.env.SHOPIFY_API_KEY,
    API_SECRET_KEY: process.env.SHOPIFY_API_SECRET,
    SCOPES: process.env.SHOPIFY_API_SCOPES.split(","),
    HOST_NAME: process.env.SHOPIFY_APP_URL.replace(/https:\/\//, ""),
    API_VERSION: ApiVersion.April21,
    IS_EMBEDDED_APP: true,
    SESSION_STORAGE: new Shopify.Session.CustomSessionStorage(
        RedisSessionStorage.storeCallback,
        RedisSessionStorage.loadCallback,
        RedisSessionStorage.deleteCallback,
    ),
});

const port = parseInt(process.env.PORT, 10) || 3001;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
const ACTIVE_SHOPIFY_SHOPS = {[process.env.ACTIVE_SHOPIFY_SHOP]: process.env.SHOPIFY_API_SCOPES}

app.prepare().then(() => {
    const server = new Koa();
    const router = new Router();
    server.keys = [Shopify.Context.API_SECRET_KEY];

    server.use(
        shopifyAuth({
            accessMode: 'offline',
            afterAuth(ctx) {
                const { shop, scope, accessToken } = ctx.state.shopify;
                global.accessToken = accessToken

                ACTIVE_SHOPIFY_SHOPS[shop] = scope;

                ctx.redirect(`/?shop=${shop}`);
            },
        }),
    );

    const handleRequest = async (ctx) => {
        await handle(ctx.req, ctx.res);
        ctx.respond = false;
        ctx.res.statusCode = 200;
    };

    router.get("/", async (ctx) => {
        const shop = ctx.query.shop;
        if (ACTIVE_SHOPIFY_SHOPS[shop] === undefined) {
            ctx.redirect(`/auth?shop=${shop}`);
        } else {
            await handleRequest(ctx);
        }
    });

    router.get("(/_next/static/.*)", handleRequest);
    router.get("/_next/webpack-hmr", handleRequest);

    router.get("(.*)", verifyRequest({accessMode: 'offline'}), handleRequest);

    server.use(router.allowedMethods());
    server.use(router.routes());

    server.listen(port, () => {
        console.log(`> Ready on http://localhost:${port}`);
    });
});
EN

回答 1

Stack Overflow用户

发布于 2021-06-10 04:29:09

您试过使用默认的SESSION_STORAGE吗?看上去像是指向/auth

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67888973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档