模块导出,nodejs对于护照身份验证需要太长时间

问题描述 投票:0回答:1

我试图通过passport-facebook验证用户,并且有一件非常奇怪的事情发生,我真的不确定。在定义我的路线时,我有这行代码

 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)

  }
))

问题是

为什么当我写作

app.get('/login/facebook',
        IsAuth.facebookEnter ),

它不起作用,但如果我写这个代码

app.get('/login/facebook',
            passport.authenticate('facebook') ),

那它有效,为什么呢?我的JWT护照认证工作正常,即使使用相同的文件夹结构如何使其工作并将passport.authenticate保存在单独的文件中?

javascript node.js facebook authentication backend
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.