Итак, я узнаю об node.js и аутентификации на Facebook, и я столкнулся с этой ошибкой:
/home/lindan4/Git/HelloNodeJS/ChatTime/node_modules/passport-oauth2/lib/strategy.js:79
if (!verify) { throw new TypeError('OAuth2Strategy requires a verify callback'); }
^
TypeError: OAuth2Strategy requires a verify callback
at Strategy.OAuth2Strategy (/home/lindan4/Git/HelloNodeJS/ChatTime/node_modules/passport-oauth2/lib/strategy.js:79:24)
at new Strategy (/home/lindan4/Git/HelloNodeJS/ChatTime/node_modules/passport-facebook/lib/strategy.js:55:18)
at module.exports (/home/lindan4/Git/HelloNodeJS/ChatTime/app/auth/index.js:42:16)
at Object.<anonymous> (/home/lindan4/Git/HelloNodeJS/ChatTime/server.js:3:22)
at Module._compile (internal/modules/cjs/loader.js:707:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
at Module.load (internal/modules/cjs/loader.js:605:32)
at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
at Function.Module._load (internal/modules/cjs/loader.js:536:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
at startup (internal/bootstrap/node.js:308:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:878:3)
Вот код:
'use strict';
const passport = require('passport');
const config = require('../config');
const FacebookStrategy = require('passport-facebook').Strategy;
const helper = require('../helpers');
module.exports = () => {
passport.serializeUser((user, done) => {
done(null, user.id);
});
passport.deserializeUser((id, done) => {
helper.findById(id).then(user => {
done(null, user);
}).catch('Error deserializing user');
});
//Issue is here
let authProcessor = (accessToken, refreshToken, profile, done) => {
//Find a user in the local MongoDB instance using the profile.id
helper.findRecord(profile.id).then(result => {
if (result)
{
done(null, result);
}
else
{
//Create a new user and return
helper.createNewUser(profile).then(newChatUser => {
done(null, newChatUser)
}).catch(error => console.log('Error when creating new user'));
}
});
}
passport.use(new FacebookStrategy(config.fb), authProcessor);
}
Ошибка заключается в этой строке:
passport.use(new FacebookStrategy(config.fb), authProcessor);
Я просмотрел Google и Stack Overflow и пока не нашел решения.Я надеялся, что кто-то может мне помочь.Для справки, модуль "config" реализован так, как показано ниже:
'use strict';
const devEnv = require('./development.json');
if (process.env.NODE_ENV === 'production')
{
//Offer production stage environment variables
module.exports =
{
host: process.env.host || "",
dbURI: process.env.dbURI,
sessionSecret: process.env.sessionSecret,
fb: {
clientID: process.env.fbClientID,
clientSecret: process.env.fbClientSecret,
callbackURL: process.env.host + "auth/facebook/callback",
profileFields: ['id', 'displayName', 'photos']
}
}
}
else
{
//Offer dev stage and data
module.exports = {
host: devEnv.host,
dbURI: devEnv.dbURI,
sessionSecret: devEnv.sessionSecret
}
}