Advanced Node and Express - Serialization of a User Object

I want to need help. I am doing my assignment Serialization of a User Object and could not pass test Serialize user function correct.Getting error => There should be a callback in your serializeUser with (null, user._id) .Can someone help me what i am doing wrong??
Code of my server.js file is =>

'use strict';

const express     = require('express');
const bodyParser  = require('body-parser');
const fccTesting  = require('./freeCodeCamp/fcctesting.js');

const session= require('express-session');
const passport=require('passport');

const db=require('mongodb').MongoClient;
const objectId=require('mongodb').ObjectID;


const app = express();
app.set('view engine','pug')
fccTesting(app); //For FCC testing purposes
app.use('/public', express.static(process.cwd() + '/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.route('/')
  .get((req, res) => {
    res.render(process.cwd() + '/views/pug/index.pug',{title:'Hello',message:'Please login'});
  });

app.use(session({
  secret:process.env.SESSION_SECRET,
  resave:true,
  saveUninitialized:true
}))
app.use(passport.initialize())
app.use(passport.session())

db.connect(process.env.MONGO,(err,data)=>{
  if (err){return err}
  else{
   passport.serializeUser((user,done)=>{  
     return  done(null,user._id)
   })

    passport.deserializeUser((id, done) => {
        db.collection('user').findOne(
            {_id: new objectId(id)},
            (err, doc) => {
               return  done(null, null);
            }
        );
    });
    }
})


app.listen(process.env.PORT || 3000, () => {
  console.log("Listening on port " + process.env.PORT);
});

Solved by my self.
There is a mistake in passport.serializeUser(function) . It needs a space between the comma (,) and user._id to pass the test i.e return done(null, user._id).

2 Likes

Can you send me the link that you correct about glitch please

Thank you for this ! I was trying to figure out myself as well what I have done