You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js中bigcommerceSigned.verifyJWT不是函数问题求助

解决bigcommerceSigned.verifyJWT is not a function报错问题

问题背景

在遵循BigCommerce官方step-2教程开发应用时,遇到如下报错:

{"message":"bigcommerceSigned.verifyJWT is not a function"}

涉及的lib/auth.ts代码如下:

import * as BigCommerce from 'node-bigcommerce';

// Create BigCommerce instance
// https://github.com/bigcommerce/node-bigcommerce/
const bigcommerce = new BigCommerce({
    logLevel: 'info',
    clientId: process.env.CLIENT_ID,
    secret: process.env.CLIENT_SECRET,
    callback: process.env.AUTH_CALLBACK,
    responseType: 'json',
    headers: { 'Accept-Encoding': '*' },
    apiVersion: 'v3'
});

const bigcommerceSigned = new BigCommerce({
    secret: process.env.CLIENT_SECRET,
    responseType: 'json'
});

interface QueryParams {
    [key: string]: string;
}

export function getBCAuth(query: QueryParams) {
    return bigcommerce.authorize(query);
}

export function getBCVerify({ signed_payload_jwt }: QueryParams) {
    return bigcommerceSigned.verifyJWT(signed_payload_jwt);
}

解决方案

1. 对齐教程依赖版本

该报错大概率是因为你安装的node-bigcommerce版本与教程指定版本不匹配,API方法名或结构发生了变更。找到教程仓库package.json中node-bigcommerce的版本号,执行安装命令:

npm install node-bigcommerce@<教程对应版本号>

2. 手动实现JWT验证(绕过库版本问题)

如果不想调整库版本,可以直接使用jsonwebtoken库手动验证签名:

  • 安装依赖:
    npm install jsonwebtoken
    
  • 修改getBCVerify函数:
    import jwt from 'jsonwebtoken';
    
    // ... 保留原有bigcommerce实例及其他代码 ...
    
    export function getBCVerify({ signed_payload_jwt }: QueryParams) {
        return jwt.verify(signed_payload_jwt, process.env.CLIENT_SECRET!, {
            algorithms: ['HS256']
        });
    }
    

3. 修正实例初始化配置

部分node-bigcommerce版本要求初始化JWT验证实例时指定auth类型,修改bigcommerceSigned的初始化代码:

const bigcommerceSigned = new BigCommerce({
    secret: process.env.CLIENT_SECRET,
    responseType: 'json',
    auth: 'jwt'
});

内容的提问来源于stack exchange,提问作者SKS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 04:55:23