Node.js 护照don';t重定向到';故障重定向';facebook失败后
我正在使用passport通过Facebook对用户进行身份验证Node.js 护照don';t重定向到';故障重定向';facebook失败后,node.js,passport.js,passport-facebook,Node.js,Passport.js,Passport Facebook,我正在使用passport通过Facebook对用户进行身份验证 successRedirect非常有效[我正在重定向到http://localhost:3000/success#_=_],但是故障重定向没有,我得到了以下信息: FacebookAuthorizationError: Login Error: There is an error in logging you into this application. Please try again later. [I'm getting t
successRedirect
非常有效[我正在重定向到http://localhost:3000/success#_=_
],但是故障重定向
没有,我得到了以下信息:
FacebookAuthorizationError: Login Error: There is an error in logging you into this application. Please try again later.
[I'm getting this in my browser-> http://localhost:3000/auth/facebook/callback?error_code=1349003&error_message=Login+Error%3A+There+is+an+error+in+logging+you+into+this+application.+Please+try+again+later.#_=_
这些是我的设置:
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser(function (user, done) {
console.log(user);
done(null, 'this is the user');
})
passport.deserializeUser(function (id, done) {
console.log(id);
done(err, {message: 'this is the user'});
});
router.get('/auth/facebook', passport.authenticate('facebook'));
router.get(
'/auth/facebook/callback',
passport.authenticate('facebook',
{
successRedirect: '/success',
failureRedirect: '/login',
}
),
);
const FacebookStrategy = require('passport-facebook').Strategy;
const facebookStrategy = new FacebookStrategy({
clientID: staretegy.clientId,
clientSecret: staretegy.clientSecret,
callbackURL: staretegy.callbackURL,
profileFields: [
'id',
'first_name',
'middle_name',
'last_name',
],
}, (accessToken, refreshToken, profile, done) => {
done(null, {user: profile});
});
passport.use(facebookStrategy);
当我在文档中阅读时,我希望被重定向到/login.
/login
可通过浏览器访问。(我还尝试将此完整URL路径设置为:failureRedirect:http://localhost:3000/login
但它不起作用,类似的URL可以与成功重定向一起工作
这似乎是一个错误,而且主存储库几乎不受支持。但您可以尝试使用。我遇到了类似的问题,并找到了使用middl处理错误的方法软件错误处理程序(请参阅下面的fbErrorHandler):
const express = require('express'),
router = express.Router(),
passport = require('passport');
router.get(
'/facebook',
passport.authenticate('facebook')
);
function fbErrorHandler(err, req, res, next) {
// I use flash, but use whatever you want to communicate with end-users:
req.flash('error', 'Error while trying to login via Facebook: ' + err);
res.redirect('/login');
}
router.get('/facebook/callback',
passport.authenticate(
'facebook',
{
failureRedirect: '/login',
failureFlash: true
},
),
fbErrorHandler,
(req, res) => {
// Successful authentication
res.redirect('/authenticated');
}
);
module.exports = router;