Hi FCC community,
I have issue with this challenge.
Here is what I have tried so far:
- 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.
- 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.