Search code examples
node.jsexpressauthenticationexpress-validator

Express validator validatorResult is not a function


validationResult is not working well and returns typeError validatorResult is not a function

i set up every thing it is working when i need to log in is the problem with express-validator

const bycrypt = require('bcryptjs');
const User = require("../util/db").user;
const {validatorResult} = require('express-validator');

        exports.postLogin = (req, res) => {
          const email = req.body.email;
          const password = req.body.password;
          const error = validatorResult();
          if (!error.isEmpty()) {
            res.status(422).render("login", {
              title: "login",
              path: "/login",
              errorMassege: error.array()
            });
          }
          User.findOne({email:email})
            .then(user => {
              if (!user) {
                req.flash("error", "invalid email or password");
                return res.redirect("/login");
              }
              bycrypt.compare(password, user.password)
              .then((doMatch)=>{
                if (!doMatch) {
                   req.flash('error','invalid email or password');
                   return res.redirect("/login");
                }
                req.session.isLogIn = true;
                res.redirect("/");
              }).catch((err)=>{
                res.redirect('/login');
                console.log(th)
              });
            })
            .catch(err => {
              res.redirect("/login");
              console.log("error is ocured", err);
            });
        };

        // the login rout is 
        route.post("/login", check("email").isEmail(), Auth.postLogin);

i expected to be done validatorResult as function but it responded not a function


Solution

  • It seems that there is a typo. It should be validationResult instead of validatorResult.

    So

    const {validationResult} = require('express-validator');