Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/register', (req, res) => {
- const {errors, isValid} = validateRegisterInput(req.body);
- if(!isValid) {
- return res.status(400).json(errors);
- }
- User.findOne({email: req.body.email})
- .then(user => {
- if(user) {
- errors.email = 'Email already exists';
- return res.status(400).json(errors);
- }
- const newUser = new User({
- name: req.body.name,
- email: req.body.email,
- avatar,
- password: req.body.password
- })
- bcrypt.genSalt(10, (err, salt) => {
- bcrypt.hash(newUser.password, salt, (err, hash) => {
- if(err) throw err;
- newUser.password = hash;
- newUser.save()
- .then(user => res.json(user))
- .catch(err => console.log(err))
- })
- })
- }
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement