我是Nodejs的初学者。我正在尝试使用facebook-authentication来做一个简单的App。我在Strategy.parseErrorResponse中遇到了错误。我给了App Id,secret这样的凭据正确输入密钥,我也已签入auth / index.js文件,但找不到发生错误的错误。谁能解决这个错误?预先感谢...
https://github.com/Mackvigneshahead/ChatApp
Error
at Strategy.parseErrorResponse (E:\STUDIES\Node Technologies\All about NodeJS\chatcat\node_modules\passport-facebook\lib\strategy.js:199:12)
at Strategy.OAuth2Strategy._createOAuthError (E:\STUDIES\Node Technologies\All about NodeJS\chatcat\node_modules\passport-oauth2\lib\strategy.js:376:16)
at E:\STUDIES\Node Technologies\All about NodeJS\chatcat\node_modules\passport-oauth2\lib\strategy.js:166:45
at E:\STUDIES\Node Technologies\All about NodeJS\chatcat\node_modules\oauth\lib\oauth2.js:191:18
at passBackControl (E:\STUDIES\Node Technologies\All about NodeJS\chatcat\node_modules\oauth\lib\oauth2.js:132:9)
at IncomingMessage.<anonymous> (E:\STUDIES\Node Technologies\All about NodeJS\chatcat\node_modules\oauth\lib\oauth2.js:157:7)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
app/auth/index.js:
'use strict';
const passport=require('passport');
const passsportfacebook=require('passport-facebook').Strategy;
const config=require('../config');
const helpers=require('../helpers');
module.exports=()=>{
passport.serializeUser((user,done)=>{
done(null,user.id);
});
passport.deserializeUser((id,done)=>{
helpers.findById(id).then((user)=>{
done(null,user);
}).catch((err)=>{
console.log('Error when deserializing the user');
console.log(err);
});
});
const authprocess=(accesstoken,refreshtoken,profile,done)=>{
helpers.findone(profile).then((result)=>{
if(result){
console.log('User found');
done(null,result);
}
else{
console.log('User not found');
helpers.newUser(profile).then((result)=>{
console.log('Created a user successfully');
done(null,result);
}).catch((error)=>{
console.log(`Error found while creating a new user: ${error}`);
});
}
});
}
passport.use(new passsportfacebook(config.fb,authprocess));
}
app/helpers/index.js:
'use strict';
const express=require('express');
const router=express.Router();
const db=require('../db');
console.log('helpers/index outside');
let _registerRoutes=(routes,method)=>{
for(let key in routes){
if( (typeof routes[key] === 'object') && (routes[key] !==null) && !( routes[key] instanceof Array)){
_registerRoutes(routes[key],key);
}
else{
if(method === 'get'){
console.log('get in');
router.get(key,routes[key]);
}
else if(method ==='post'){
console.log('post in');
router.post(key,routes[key]);
}
else{
router.use(routes[key]);
}
}
}
return router;
}
let findone=(profileId)=>{
return db.userchatdetails.findOne({'profileId':profileId});
}
let findById=(id)=>{
return new Promise((resolve,reject)=>{
db.userchatdetails.findById(id,(error,user)=>{
if(error){
return reject(error);
}
else{
return resolve(user);
}
});
});
};
let newUser=(profile)=>{
return new Promise((resolve,reject)=>{
const user= new db.userchatdetails({
profileId:profile.id,
fullname:profile.displayName,
profilePic:profile.photos[0].value || ''
});
user.save((error)=>{
if(error){
console.log(`Error in Mongoose: ${error}`);
reject(error);
}
else{
console.log('User data successfully');
resolve(user);
}
});
});
}
let route12=routes=>{
console.log('helpers/index inside');
console.log('calling registerroutes');
let x= _registerRoutes(routes);
return x;
}
module.exports={
route12,
findone,
newUser,
findById
};