req.isAuthenticated() is always false
Try changing the order of
app.use(passport.initialize());app.use(passport.session());app.use(require("express-session")({ secret: "Rusty is the worst and ugliest dog in the wolrd", resave: true, saveUninitialized: true}));
to
app.use(require("express-session")({ secret: "Rusty is the worst and ugliest dog in the wolrd", resave: true, saveUninitialized: true}));app.use(passport.initialize());app.use(passport.session());
If you are using cookies make sure you add cookie-parser middleware
var express = require('express')var cookieParser = require('cookie-parser')var app = express()app.use(cookieParser())
If this is not the case check you calling end, if you are using axios include withCredentials
axios.get('some api url', {withCredentials: true});
if you are uisg fetch make sure to add credentials: 'include'
fetch('/...', { method: .., headers: ..., credentials: 'include', body: ... ...})
Starting with version 0.2.1 passport-local-mongoose adds a helper method createStrategy as static method to your schema. The createStrategy is responsible to setup passport-local LocalStrategy with the correct options.
const User = require('./models/user');// CHANGE: USE "createStrategy" INSTEAD OF "authenticate"passport.use(User.createStrategy());passport.serializeUser(User.serializeUser());passport.deserializeUser(User.deserializeUser());