Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda