【发布时间】:2026-02-14 01:05:01
【问题描述】:
我正在制作一个应用程序,用户可以通过转到 /mysafe 来创建保险箱。但我只想在他第一次去那里时创建它,下次他去 /mysafe 时它应该重定向到 /mysafe/theidofit。
查看我的 app.js
app.get('/mysafe',async (req,res)=> {
const safe=new Safe()
safe.author=req.user._id
safe.save()
res.redirect(`/mysafe/${safe._id}`)
})
我尝试添加中间件,但在我的用户架构中我没有定义安全。我需要定义它还是没有它可以做到吗?
const UserSchema = new Schema({
email: {
type: String,
required: true,
unique: true
}
});
【问题讨论】:
-
你在使用猫鼬吗?
-
是的,我正在使用猫鼬
标签: javascript mongodb express mongoose ejs