Hi, folks. For some reason, I can’t seem to pass the final requirement of this challenge, “MongoDB properly required, including the ObjectId.”
My code so far:
"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');
// This is the line that should satisfy the requirement.
// I also tried this with require('mongodb').ObjectId,
// since it's spelled that way in the failed requirement.
const ObjectID = require('mongodb').ObjectID;
const app = express();
app.use(session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser((user, done) => {
done(null, user._id);
});
passport.deserializeUser((id, done) => {
// db.collection('users').findOne(
// {_id: newObjectID(id)}, (err, doc) => {
// done(null, null);
// })
done(null, null);
})
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.set("view engine", "pug");
app.route("/").get((req, res) => {
res.render(process.cwd() + "/views/pug/index.pug", {
title: "Hello",
message: "Please login"
});
});
app.listen(process.env.PORT || 3000, () => {
console.log("Listening on port " + process.env.PORT);
});
I’ve even gone looking for other people’s working code and copy-pasted that line. Also tried requiring just mongodb by itself separately. Still no luck. Any advice would be greatly appreciated.
The full project can be found here: https://glitch.com/edit/#!/luos-fcc-advanced-node-and-express. I do have an outdated version of mongodb as a dependency, but updating it makes every part of the challenge fail…
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/learn/information-security-and-quality-assurance/advanced-node-and-express/serialization-of-a-user-object