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?