How to Use Passport Strategies - Please help with the issue

Hi FCC community,
I have issue with this challenge.

Here is what I have tried so far:

  1. So I know that they have mentioned " If you’re running into errors, you can check out the project completed up to this point here." but that did not work.
  2. I have googled and I have tried many different scenarios and it is just not working.

Here is my code so far for server.js

'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 ObjectID    = require('mongodb').ObjectID;
const mongo       = require('mongodb').MongoClient;
const LocalStrategy = require('passport-local')

const app = express();


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

// # 1 question 
app.set('view engine', 'pug')

// #2 question 
app.use(session({
  secret: process.env.SESSION_SECRET,
  resave: true,
  saveUninitialized: true,
}));
app.use(passport.initialize());
app.use(passport.session());

// #3 question
mongo.connect(process.env.DATABASE, (err, db) => {
  if(err) {
    console.log('Database error: ' + err);
  } else {
    console.log('Successful database connection');

    //serialization and app.listen
  }
});

// #4 question 

passport.use(new LocalStrategy(
  function(username, password, done) {
    db.collection('users').findOne({ username: username }, function (err, user) {
      console.log('User '+ username +' attempted to log in.');
      if (err) { return done(err); }
      if (!user) { return done(null, false); }
      if (password !== user.password) { return done(null, false); }
      return done(null, user);
  });
  }
));

// # 5 question 

app.route('/login').post(passport.authenticate('local', { failureRedirect: '/' }), 
      (req, res) => {
        console.log('Login Route: User logged in, redirecting to profile.')
      res.redirect('/profile')
    })


//the rest of the code

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

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

Also, I wanted to ask you, why am I seeing the error when I try to look over my code and glitch stuff which is here ?

I have passed all of the challenges so far until this one but I am seeing an error.

Any help is greatly appreciated.

I have resolved the issue myself

Here is code that worked for me for this challenge

'use strict';

const express = require('express');
const bodyParser = require('body-parser');
const fccTesting = require('./freeCodeCamp/fcctesting.js');
const pug = require('pug')
const passport = require('passport');
const app = express();
const session = require('express-session');
const mongo = require('mongodb').MongoClient;
const ObjectID = require('mongodb').ObjectId
const LocalStrategy = require('passport-local').Strategy;
fccTesting(app)

process.env.SESSION_SECRET = "lll"
process.env.ENABLE_DELAYS = true
process.env.DATABASE = 'mongodb://wadeabel:Helloworld1@ds125293.mlab.com:25293/mydatabase';

app.set('view engine', 'pug')

app.use('/public', express.static(process.cwd() + '/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: true
}));
app.use(session({
    secret: process.env.SESSION_SECRET,
    resave: true,
    saveUninitialized: true
}))
app.use(passport.initialize())
app.use(passport.session())


function ensureAuthenticated(req, res, next) {

    if (req.isAuthenticated()) {

        return next()
    }


    res.redirect('/')
}


mongo.connect(process.env.DATABASE, {
    useNewUrlParser: true
}, (err, client) => {
    const db = client.db('mydatabase')
    if (err) {
        console.log('Database error' + err)
    } else {
        console.log('connect success')




        passport.serializeUser((user, done) => {
            done(null, user._id)
        })


        passport.deserializeUser((id, done) => {
            db.collection('users').findOne({
                    _id: new ObjectID(id)
                }, function(err, doc) {
                    done(null, doc)

                }

            )
        })


        passport.use(new LocalStrategy(
            function(username, password, done) {
                db.collection('users').findOne({
                    username: username
                }, function(err, user) {
                    console.log('User' + username + " attempted to log in");
                    if (err) {
                        return done(err)
                        console.log(err)
                    }
                    if (!user) {
                        return done(null, false)
                        console.log('ohoh')
                    }
                    if (password !== user.password) {
                        return done(null, false)
                        console.log('ohoh')
                    }
                    console.log('ohoh')
                    return done(null, user)

                })
            }
        ))



        app.get('/', (req, res) => {
            res.render(process.cwd() + '/views/pug/index', {
                title: 'Home page',
                message: 'Please login',
                showLogin: true,
                showRegistration: true
            });
        });


        app.post('/login', passport.authenticate('local', {
            failureRedirect: '/'
        }), (req, res) => {
            res.redirect('/profile')
        })


        app.get('/profile', ensureAuthenticated, (req, res, next) => {

            console.log(req)
            res.render(process.cwd() + '/views/pug/profile', {
                username: req.user.username
            })

        })

        app.route('/register').
        post((req, res, next) => {
                db.collection('users').findOne({
                    username: req.body.username
                }, function(err, user) {
                    if (err) {
                        next(err)
                        console.log(err)

                    } else if (user) {
                        res.redirect('/');
                    } else {
                        console.log('hi')
                        db.collection('users').insertOne({
                                username: req.body.username,
                                password: req.body.password
                            },
                            (err, doc) => {
                                if (err) {
                                    res.redirect('/');
                                    console.log(err)
                                } else {
                                    next(null, user);
                                }
                            }
                        )
                    }
                })
            },
            passport.authenticate('local', {
                failureRedirect: '/'
            }),
            (req, res, next) => {

                console.log('letmeout')
                res.redirect('/profile');
            }
        );




        app.get('/logout', (req, res) => {
            req.logout();
            res.redirect('/');
        })




        app.use((req, res, next) => {
            res.status(404).type('text').send('No Found');
        })


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