In the project I'm working on, there is a feature where a user can create a safe by visiting /mysafe. However, I want this safe to be created only once when they first visit the page. Subsequent visits should redirect them to /mysafe/theidofit.
Have a look at my app.js:
app.get('/mysafe',async (req,res)=> {
const safe=new Safe()
safe.author=req.user._id
safe.save()
res.redirect(`/mysafe/${safe._id}`)
})
I attempted to add a middleware for this functionality, but since my user schema does not have a 'safe' property defined, I'm unsure if I need to define it or if there's another way around it.
const UserSchema = new Schema({
email: {
type: String,
required: true,
unique: true
}
});