模块导出,nodejs 需要太长时间才能进行护照身份验证
Module exports, nodejs takes too long for passport auth
我正在尝试通过 passport-facebook 对用户进行身份验证,但发生了 1 件非常奇怪的事情,我真的不确定。
在定义我的路线时,我有这行代码
app.get('/login/facebook',
IsAuth.facebookEnter ),
//passport.authenticate('facebook')
app.get('/login/facebook/return',
IsAuth.facebookComeBack)
在我的 IsAuth 文件中我有以下内容
const passport = require('passport')
const FacebookStrategy = require('../passport/facebook_passport')
module.exports = {
facebookEnter(){
passport.authenticate('facebook')
},
facebookComeBack(){
passport.authenticate('facebook', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
}
}
}
这里是策略本身
const passport = require('passport')
const User = require('../models/User')
const FacebookStrategy = require('passport-facebook')
passport.use(new FacebookStrategy({
clientID: "ALMOST POSTED IT",
clientSecret: "Ntest test",
//call baack to one of our routes to valiate the auth request
//is called when the user pressed on OK to login with facebook
callbackURL: "http://localhost:8888/login/facebook/return"
},
function(accessToken, refreshToken, profile, cb) {
console.log(profile, accessToken, refreshToken)
}
))
The question is
为什么我写
app.get('/login/facebook',
IsAuth.facebookEnter ),
它不起作用但是如果我写这段代码
app.get('/login/facebook',
passport.authenticate('facebook') ),
然后就可以了,为什么?即使使用相同的文件夹结构,我的 JWT 护照身份验证也能按预期正常工作
我怎样才能使它工作并将 passport.authenticate 保存在一个单独的文件中?
我的可以用这个!分割出口。
module.exports.fbAuth = passport.authenticate("facebook");
module.exports.fbAuthCB = function(req, res, next) {
passport.authenticate("facebook", (err, user, info) =>
generateTokenAndRedirect(err, user, info, req, res, next)
)(req, res);
};
router.get("/auth/facebook", authCtrl.fbAuth);
router.get("/auth/facebook/callback", authCtrl.fbAuthCB);
我正在尝试通过 passport-facebook 对用户进行身份验证,但发生了 1 件非常奇怪的事情,我真的不确定。 在定义我的路线时,我有这行代码
app.get('/login/facebook',
IsAuth.facebookEnter ),
//passport.authenticate('facebook')
app.get('/login/facebook/return',
IsAuth.facebookComeBack)
在我的 IsAuth 文件中我有以下内容
const passport = require('passport')
const FacebookStrategy = require('../passport/facebook_passport')
module.exports = {
facebookEnter(){
passport.authenticate('facebook')
},
facebookComeBack(){
passport.authenticate('facebook', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
}
}
}
这里是策略本身
const passport = require('passport')
const User = require('../models/User')
const FacebookStrategy = require('passport-facebook')
passport.use(new FacebookStrategy({
clientID: "ALMOST POSTED IT",
clientSecret: "Ntest test",
//call baack to one of our routes to valiate the auth request
//is called when the user pressed on OK to login with facebook
callbackURL: "http://localhost:8888/login/facebook/return"
},
function(accessToken, refreshToken, profile, cb) {
console.log(profile, accessToken, refreshToken)
}
))
The question is
为什么我写
app.get('/login/facebook',
IsAuth.facebookEnter ),
它不起作用但是如果我写这段代码
app.get('/login/facebook',
passport.authenticate('facebook') ),
然后就可以了,为什么?即使使用相同的文件夹结构,我的 JWT 护照身份验证也能按预期正常工作 我怎样才能使它工作并将 passport.authenticate 保存在一个单独的文件中?
我的可以用这个!分割出口。
module.exports.fbAuth = passport.authenticate("facebook");
module.exports.fbAuthCB = function(req, res, next) {
passport.authenticate("facebook", (err, user, info) =>
generateTokenAndRedirect(err, user, info, req, res, next)
)(req, res);
};
router.get("/auth/facebook", authCtrl.fbAuth);
router.get("/auth/facebook/callback", authCtrl.fbAuthCB);