Advanced Node and Express - Set up Passport

Tell us what’s happening:

The server starts up and runs fine locally, I’ve created and populated my .env file (tried all sorts of string/numeric values for SESSION_SECRET), and I’ve added session handling with Passport configured. Everything looks correct, but the FCC tests still fail.

Earlier I had an issue with a missing package (fixed with npm install cors) that caused tests to fail even though the app worked in the browser, so I’m wondering if this step has a similar requirement or if the tests are expecting something very specific. I’ve checked all relevant previous forum posts, but couldn’t find a solution.

Thanks!

Your code so far

.env

PORT=8080
NODE_ENV=development
MONGO_URI='myURI'
SESSION_SECRET=superSecretString

server.js

'use strict';
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const session = require('express-session');
const passport = require('passport');
const myDB = require('./connection');
const fccTesting = require('./freeCodeCamp/fcctesting.js');

const app = express();

fccTesting(app); // For fCC testing purposes

app.set('view engine', 'pug');
app.set('views', './views/pug');

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

app.use(cors());
app.use('/public', express.static(process.cwd() + '/public'));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.route('/').get((req, res) => {
  res.render('index', { title: 'Hello', message: 'Please log in' });
});

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36

Challenge Information:

Advanced Node and Express - Set up Passport