I've worked through other Stack Overflow posts about the "Unknown authentication strategy" error, but none of the posted solutions solved my problem. I've used the passport.js tutorial at https://www.passportjs.org/howtos/password/ as a guide while trying to enable user authentication for my Express/MongoDB web application, but have been unable to progress due to this error.
I'm receiving the below error in the browser when I click 'Submit' after typing in an email and password to my form:
I'm also receiving the below errors in the console:
Below is code in my auth.js file, which defines the passport strategy and handles creating sessions with serializeUser and deserializeUser. The verify function I'm passing into the LocalStrategy constructor isn't entirely developed. I wanted to ensure that passport.js would at least return an error message when it didn't find the testemail@test.com email in MongoDB before writing the code that would determine when a user's email was actually in the database.
const express = require('express');
const passport = require('passport');
const LocalStrategy = require('passport-local')
const { MongoClient } = require("mongodb");
const url = mongoDBConnectionString; // I have inserted a placeholder for my connection string because I don't want to post it on Stack Overflow.
const client = new MongoClient(url);
passport.use(new LocalStrategy(async function verify(email, password, cb) {
await client.connect(); // Connect to the MongoDB Atlas instance at the above url.
const db = client.db("users"); // Connect to the "users" database.
const col = db.collection("userLogins"); // Use the collection "userLogins".
const user = await col.findOne({email_address: email}); // Determine if a user exists with a specific email address.
await client.close();
return cb(null, false, { message: "Incorrect username or password."});
passport.serializeUser(function(user, cb) {
process.nextTick(function() {
return cb(null, { id: user.id, username: user.username });
});
});
passport.deserializeUser(function(user, cb) {
process.nextTick(function() {
return cb(null, user);
});
});
Below is the code in my app.js file where I have the "/login/password" POST route defined.
const express = require('express')
const session = require('express-session');
const passport = require('passport');
const LocalStrategy = require('passport-local')
const bodyParser = require('body-parser');
const { MongoClient } = require("mongodb");
const app = express();
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: false,
cookie: { secure: true }
}));
app.use(passport.authenticate('session'));
.
.
.
.
app.post('/login/password', passport.authenticate('local', {
successReturnToOrRedirect: '/',
failureRedirect: '/login',
failureMessage: true
}));


