hey I want to make sure if I use the correct way for middleware in my simple express app, I am trying to find the email unique for register here is my example
const isUnique = (req, res, next) => { User.findOne({ where:{ email: req.body.email } }) .then(getUser => { if(getUser){ next("/userAlreadyExist") // router // or can i render to to html? i am using ejs } else { next() } }) .catch(next()) } app.post('/register', isUnique ,(req, res) => { res.send(`thank you for register`) } I want to make sure the email already exists or no, so I want to pass it on middleware first, and get a page for isUnique, if the email already in use, I want to redirect it to next router called '/emailExist', and if it success i want to redirect it to router /success can anyone help me if that code wrong or no? just want to make sure :D