问题描述
我正在尝试在提交表单时对用户的Firebase ID进行哈希处理,因为该ID将传递给以后的查询以查找数据库条目。
这只是为了提高安全性(尽管不能完全确定,因为该身份验证是由Firebase身份验证处理的)。
我正在使用无服务器功能在React Web应用程序中执行此操作。我要Bcrypt散列通过req.body传递的“ firebaseId”(我为此设置了页面加载状态)。
但是,提交表单后,出现以下错误:
TypeError: Cannot read property 'firebaseId' of undefined
at model.<anonymous> (/var/task/api/submitDebtSchema.js:20:25)
at callMiddlewareFunction (/var/task/node_modules/kareem/index.js:482:23)
at model.next (/var/task/node_modules/kareem/index.js:58:7)
at _next (/var/task/node_modules/kareem/index.js:106:10)
at /var/task/node_modules/kareem/index.js:507:38
at processticksAndRejections (internal/process/task_queues.js:79:11)
这是我的架构:
const SubmitDebtSchema = new Schema ({
firebaseId: String
});
SubmitDebtSchema.pre("save",function(req,res,next) {
bcrypt.hash(req.body.firebaseId,10,(error,hash) => {
req.body.firebaseId = hash;
next();
});
});
module.exports = mongoose.model('submitdebt',SubmitDebtSchema);
我的无服务器功能发布了架构:
module.exports = async (req,res) => {
res.statusCode = 200;
res.setHeader("Content-Type","application/json");
await SubmitDebt.create(req.body)
.then(() => {
res.send(JSON.stringify({ success: true }));
})
.catch((err) => {
console.log(err);
res.send(JSON.stringify({ success: false }));
});
};
我的前端Axios帖子:
await axios.post("/api/submitDebt",{
firebaseId: this.state.firebaseId
})
(为简单起见,我删除了其他条件)
有人可以指出我要去哪里了吗?谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)