After extensive research online, I have yet to find a solution to my issue. Therefore, I am reaching out here for assistance.
I am currently working on implementing sessions with Passport. The registration and login functionalities are functioning properly. However, the problem lies in the fact that req.isAuthenticated always returns false.
I have attempted the usual troubleshooting steps:
Ensuring app.use(passport.session()) is placed after the express-session configuration:
...
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({
secret: 'somethingsomethingdarkside',
cookie: { maxAge: 1209600000 },
saveUninitialized: false,
resave: false,
// using store session on MongoDB using express-session + connect
store: new MongoStore({
url: configDB.url,
collection: 'sessions'
})
}));
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
...
I delved into Passports request.js file for debugging purposes and observed that
this[property/*user*/] = user;
successfully assigns the desired values, as expected by me.
However, whenever I execute
if (req.isAuthenticated())
it yields
this[property/*user*/] == undefined
resulting in false. Additionally, I inserted a log message to indicate when the module initializes, and it only does so once during server startup.
It appears that user.deserializeUser is never invoked either.
I am at a loss here and would greatly appreciate any guidance or assistance you can offer.