Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda