I have written the code for checking whether an user exists or not . On the basis of that, we are redirecting using res.redirect .
app.post('/UserRegister', async (req, res, next) => {
const { username, password } = req.body;
const isTheir = await User.exists({ username: username});
console.log(isTheir);
if (isTheir==true) {
return next(new AppError("User Already Registered", 501));
}
const user = new User({username});
const registeredUser = await User.register(user, password);
console.log("Going to Search Flights");
res.redirect('/searchFlights');
});
It seems that the res.redirect is not working since it's not going to searchFlights . Please help .