i’ve passed all the test but got an error when i try to login with github
TypeError: Cannot read property 'value' of null at db.collection.findAndModify
on this line: return cb(null, doc.value);
here is the link of challange and the link of my glitch project
my code at auth.js is:
const session = require('express-session');
const mongo = require('mongodb').MongoClient;
const passport = require('passport');
const GitHubStrategy = require('passport-github').Strategy;
module.exports = function (app, db) {
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser((user, done) => {
done(null, user.id);
});
passport.deserializeUser((id, done) => {
db.collection('chatusers').findOne(
{id: id},
(err, doc) => {
done(null, doc);
}
);
});
passport.use(new GitHubStrategy({
clientID: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
callbackURL: "https://environment-setup-uaaeu.glitch.me/auth/github/callback"
},
function(accessToken, refreshToken, profile, cb) {
db.collection('chatusers').findAndModify(
{id: profile.id},
{},
{$setOnInsert:{
id: profile.id,
name: profile.displayName || 'Anonymous',
photo: profile.photos[0].value || '',
email: profile.emails[0].value || 'No public email',
created_on: new Date(),
provider: profile.provider || '',
chat_messages: 0
},$set:{
last_login: new Date()
},$inc:{
login_count: 1
}},
{upsert:true, new: true}, //Insert object if not found, Return new object after modify
(err, doc) => {
return cb(null, doc.value);
}
);
}
));
}
full error log is:
/rbd/pnpm-volume/5d8704fe-2e36-48a8-9d35-45bc04172648/node_modules/mongodb/lib/utils.js:123
process.nextTick(function() { throw err; });
^
TypeError: Cannot read property 'value' of null
at db.collection.findAndModify (/app/app/auth.js:49:39)
at handleCallback (/rbd/pnpm-volume/5d8704fe-2e36-48a8-9d35-45bc04172648/node_modules/mongodb/lib/utils.js:120:56)
at /rbd/pnpm-volume/5d8704fe-2e36-48a8-9d35-45bc04172648/node_modules/mongodb/lib/collection.js:2492:22
at handleCallback (/rbd/pnpm-volume/5d8704fe-2e36-48a8-9d35-45bc04172648/node_modules/mongodb/lib/utils.js:120:56)
at /rbd/pnpm-volume/5d8704fe-2e36-48a8-9d35-45bc04172648/node_modules/mongodb/lib/db.js:314:20
at /rbd/pnpm-volume/5d8704fe-2e36-48a8-9d35-45bc04172648/node_modules/mongodb-core/lib/connection/pool.js:469:18
at process._tickCallback (internal/process/next_tick.js:61:11)