I have a mongoose schema like this
const UserSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
password: {
type: String,
required: true,
}
});
mongoose.model('User', UserSchema);
lets say we have a
/user/me route that gives the users their data if they are authenticated.
what would be the best way to prevent the password to be send to each user through an API request ? shall i remove the field from the object that i retrieve from the database ? or there are other ways to handle it better ?
P.S: I'm looking for the best way to handle it, not how to do it