Node.js/ mysql passport-facebook 认证

Node.js/ mysql passport-facebook authenticate

我正在设置一个登录页面,使用 passport-facebook 身份验证,接受来自 facebook 的电子邮件地址。但是当出现重复条目​​时,它正在重定向到成功page.Please帮助我

function(accessToken, refreshToken, profile, done) {
    process.nextTick(function() {
        if (fbconfig.use_database === true) {
            const qr = ("SELECT * from tbl_user where email ='" + profile.emails[0].value + "';");
            pool.query(qr, (err, rows) => {
                if (err) {
                    throw err;
                }
                if (rows && rows.length === 0) {
                    console.log(profile.emails[0].value);
                    console.log(profile.id);
                    console.log(profile.displayName);
                    var dt = dateTime.create();
                    var d = dt.format('Y-m-d H:M:S');
                    console.log("Creating profile");
                    let sql = ("INSERT into tbl_user(fb_id,token,name,email,cur_date) VALUES('" + profile.id + "','" + accessToken + "','" + profile.displayName + "','" + profile.emails[0].value + "','" + d + "');");
                    pool.query(sql, function(err, result) {
                        if (err) {
                            throw err;

                        }
                        console.log("fb inserted");


                    });



                } else {

                    console.log("Error Email already exist");

                }
            });

        }
        return done(null, profile);
    });
}));
router.get('/auth/facebook', passport.authenticate('facebook', { scope: 'email' }));
router.get('/auth/facebook/callback',
passport.authenticate('facebook', { successRedirect: '/sample', failureRedirect: '/', failureFlash: true }),
function(req, res) {
    pool.query(qr, (err, rows) => {
        if (err) {
            throw err;
        }
        if (rows && rows.length > 0) {
            res.render('/');
        }


    })


}
);

这是我的代码,我找不到解决方案

每当发生错误时尝试完成(错误)。

例如,尝试

if (err) {
    throw err;
}

if(err) {
    done(err);
}

希望对你有帮助。

    function(accessToken, refreshToken, profile, done) {
process.nextTick(function() {
    if (fbconfig.use_database === true) {
        const qr = ("SELECT * from tbl_user where email ='" + profile.emails[0].value + "';");
        pool.query(qr, (err, rows) => {
            if (err) {
                throw err;
            }
            if (rows && rows.length === 0) {
                console.log(profile.emails[0].value);
                console.log(profile.id);
                console.log(profile.displayName);
                var dt = dateTime.create();
                var d = dt.format('Y-m-d H:M:S');
                console.log("Creating profile");
                let sql = ("INSERT into tbl_user(fb_id,token,name,email,cur_date) VALUES('" + profile.id + "','" + accessToken + "','" + profile.displayName + "','" + profile.emails[0].value + "','" + d + "');");
                pool.query(sql, function(err, result) {
                    if (err) {
                        throw err;

                    }
                    console.log("fb inserted");


                });
return done(null, true);

            } else {

                console.log("Error Email already exist");


return done(null, false);

            }
        });

    }

});
}));
router.get('/auth/facebook', passport.authenticate('facebook', { scope: 'email' }));
router.get('/auth/facebook/callback',
passport.authenticate('facebook', { successRedirect: '/sample', failureRedirect: '/', failureFlash: true }),
function(req, res) {
res.redirect('/sample')   
}

);