Oh my god, thank you so much for this! I couldn't even get the workarounds to work for my setup.
In the end I didn't even have to add the toObject() to my Mongoose Schema. I just added that method to the req.locals in my server.js file.
app.use(function (req, res, next) { if (req.user) { res.locals.user = req.user.toObject(); } next(); });
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Oh my god, thank you so much for this! I couldn't even get the workarounds to work for my setup.
In the end I didn't even have to add the toObject() to my Mongoose Schema. I just added that method to the req.locals in my server.js file.