validationResult运行不正常,并返回typeErrorvalidatorResult不是函数
我需要登录时设置所有可以正常使用的东西 使用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);
我希望将validatorResult作为函数执行,但它没有响应
答案 0 :(得分:1)
似乎有错字。应该是validationResult
而不是validatorResult
。
所以
const {validationResult} = require('express-validator');