Answer the question
In order to leave comments, you need to log in
How to hide secret information about the user during authorization (password, id)?
I do authorization by email and password on the server side (Node.JS). All user information is retrieved from the database (MongoDB), including id and password. The password is stored in a hash format, but it still does not need to be sent to the frontend, just like the password.
I thought like this:
- make a separate userPublic object with fields that will go to the client
let dataPublic = {
name: "",
email: ""
}
module.exports = dataPublic;
Object.assign(dataPublic, dataFromDb);
Answer the question
In order to leave comments, you need to log in
PSEUDOCODE:
User.find({
email: req.body.email,
password: User.hashPassword(req.body.password)
}, (err, user) => {
if(err) {
return res.status(400).json({error: err});
}
if(user) {
let data = JSON.parse(JSON.stringify(user, ['allow', 'fields', 'in', 'array']));
return res.status(200).json(data);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question