0

im try to make register page i use post route for the info of the new user im save the new user in db then i want to redirect back to the main page but insted redirect its throw exeption

    app.post('/register', (req, res) => {
  var body = _.pick(req.body, ['Email' , 'Password' , 'First_Name' , 'Last_Name' , 'Phone_Number' , 'Address' , 'Permission']);

  if(body.Password !== req.body.confirm_password) {
    return res.render('register-user.hbs', {
      PageTitle: 'Register user',
      ConnectUser: req.cookies.fullName,
      errMsg: 'Unverified Password'
    });
  }

  var user = new User(body);

  user.save().then((user) => {
      return res.redirect('admin_main_page');

  //  res.send({user});
  }).catch((e) => {
    res.status(400).send();
    console.log("invalid input");
  });
});

i check the code on postman when i change the callback to send {user} and its work but when i try to redirect its go to the exception also when the pass and confirm pass are not the same its also do what its supose to do can any 1 tell me what im doing wrong?

shmuel
  • 13
  • 6
  • Possible duplicate of [How to redirect user's browser URL to a different page in Nodejs?](https://stackoverflow.com/questions/11355366/how-to-redirect-users-browser-url-to-a-different-page-in-nodejs) – rafaelcastrocouto Oct 02 '18 at 12:24
  • What is the output of `console.log(e)` in your catch ? – k1dbl4ck Oct 02 '18 at 12:25

0 Answers0