Set Up Passport >> Session and session secret should be correctly set up

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


const app = express();
app.set('view engine', 'pug');


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

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

app.use(passport.initialize());
app.use(passport.session());

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

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

My code above is producing setup error on session and session secret ,
But if i paste the freecodecamp solution Advanced Node and Express - Set up Passport · GitHub
it passes the challenge .

The only difference is the PORT variable.

It’s again the regex that isn’t very well written. You have a space after the key secret that isn’t accounted for.

secret: process.env.SESSION_SECRET

vs

secret : process.env.SESSION_SECRET

I should likely open an issue for it.

1 Like

You are awesome.
Yeah please do.
This one was sweaty.
My mind was confused since yesterday.
I wasted lot of time changing a lot of stuffs.
Most of new ones will too face problem i guess.
Again thanks Lasjorg :+1:

Happy to help.

Here is the issue I opened.

1 Like

Awesome !! Cheers :clinking_glasses:

1 Like