Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
Unknown authentication strategy "local" passport.js

I keep getting the Error: Unknown authentication strategy "local" error. This is a bit of my main file (server.js):

...
app.use(passport.initialize());
app.use(passport.session());
app.use(methodOverride("_method"));

...

// Initialize passport
const initializePassport = require("./passport-config");
initializePassport(
    passport,
    (email) => searchUser({ email: email }),
    (id) => searchUser({ id: id })
);

...

// Post request - Login user
app.post(
    "/login",
    checkNotAuthenticated,
    passport.authenticate("local", {
        successRedirect: "/",
        failureRedirect: "/login",
        failureFlash: true,
    })
);

this is my passport config file (passport-config.js):

const LocalStrategy = require("passport-local").Strategy;
const bcrypt = require("bcrypt");

function initialize(passport, getUserByEmail, getUserById) {
    const authenticateUser = async (email, password, done) => {
        const user = getUserByEmail(email);
        if (user == null) {
            return done(null, false, { message: "No user with that email" });
        }

        bcrypt.compare(password, user.password, function (err, result) {
            if (e) {
                return done(e);
            }
            if (result) {
                return done(null, user);
            } else {
                return done(null, false, { message: "Password incorrect" });
            }
        });

        passport.use(
            new LocalStrategy({ usernameField: "email" }, authenticateUser)
        );
        passport.serializeUser((user, done) => done(null, user.id));
        passport.deserializeUser((id, done) => {
            return done(null, getUserById(id));
        });
    };
}

module.exports = initialize;

i can't figure out whats the issue here, i'm also pretty new to passport, node and express this is not my code but i took it from a tutorial in a yt video that didn't (somehow) work, so i tried making it work, i also was trying to add mongodb storage but i dont think thats the issue

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!