NodeJS Passport本地身份验证,表单提交重定向到失败重定向URL

时间:2019-11-17 17:01:06

标签: mysql node.js redirect form-submit passport-local

我正在创建注册表,并使用护照本地身份验证。

我的代码如下:

app.post('/signup', passport.authenticate('local-signup', {
        successRedirect: '/profile',
        failureRedirect: '/signup',
        failureFlash: true
    }));

passport.use(
        'local-signup',
        new LocalStratergy({
            usernameField: 'username',
            passwordField: 'password',
            passReqToCallback: true
        },
        function(req, username, password, done){ 
            connection.query("select * from users where email_address= ?", 
            [username], function(err, rows){
                if(err)
                    return done(err);
                if(rows.length) {
                    return done(null, false, req.flash('signupMessage', 'The user with this email already exists'));
                }
                else {
                    var newUserMysql = {
                        username: username,
                        password: bcrypt.hashSync(password, null, null)
                    };
                    var insertQuery = "Insert into tbl_user (email_address, password) values (?, ?)";
                    connection.query(insertQuery, [newUserMysql.username, newUserMysql.password], 
                        function(err, rows){
                            newUserMysql.uid = rows.insertId;
                            return done(null, newUserMysql);
                        });
                }
            })
        })
    );

但是每当我提交表单时,它都会重定向到failureRedirect网址?

有人可以在这里帮助我吗?

0 个答案:

没有答案