I'm trying to build the register page (still in the beginning), and if everything will be ok, I want the client to get a message which shows success, but only after 2 seconds to move to another page. My code sends the success div but doesn't send hi to the client after 2 seconds. What is the problem?
exports.register = (req, res) => {
const { name, email, username, password, passwordConfirm} = req.body;
if (name === '' || email === '' || username === '' || password === '' || passwordConfirm === '') {
return res.render('register', {
failMessage: 'One of the fields or more is empty. Please try again.'
})
} else {
res.render('register', {
successMessage: 'User registered successfully.'
});
return setTimeout( () => {
res.send('hi');
}, 2000 );
}
};
This is the router line:
router.post('/register', authController.register);