![](/img/trans.png)
[英]How can i solve this error 'Cannot read properties of undefined (reading 'sign')' on fastify
[英]How to solve this Cannot read properties of undefined (reading 'cookies')
嘿,我收到一个错误无法读取未定义的属性(正在读取“cookies”)我创建了一个中间件 requiressigin,它将在用户登录时创建 cookies,并且同样的 function 将调用 Stripe 回调页面以获取用户 Stripe 帐户状态但我得到了过去 3 天我一直坚持的一个错误请检查
这是代码
export const requireSignin = expressjwt({
getToken:(res,req)=>req.cookies.token,
secret: process.env.JWT_SECRET,
algorithms: ["HS256"],
});
这是我在 Server.js 中的代码
app.use(cookieParser());
您可以在我的路线中查看我是如何调用它的
router.post ("/get-account-status",requireSignin,getAccountStatus);
这是我的 controller 中的代码
export const getAccountStatus = async (req, res) => {
try{
const user = await User.findById(req.user._id).exec();
const account= await stripe.accounts.retrieve(user.stripe_accound_id);
if(!account.charges_enabled)
{
return res.status(400).send("Charges Not Enabled");
}
else{
const statusUpdated= await User.findByIdAndUpdate(user._id,{
stripe_seller:account,
$addToSet:{role:'Instructor'},
},
{new:true}).select("-password").exec();
}
}
catch(err){
console.log(err);
}
}
您必须切换getToken
function 的参数顺序,所以它是(req, res)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.