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

122
Vistas
Passport Strategy is not being called

Hello SO wonderful users I am having trouble with passport js since two days and cant figure it out.

Passport Strategy is not being called. the console.log is not being called! any ideas ?

here is my code

//init.js

var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;

module.exports = function(app) {
    passport.use(new LocalStrategy(function(username, password, done) {

        console.log(username, password);
        return done(null, {username: 'agent'});
    }));

    passport.serializeUser(function(user, done) {
        done(null, 'agent');
    });

    passport.deserializeUser(function(id, done) {
        done(null, {username: 'agent'});
    });

    app.use(passport.initialize());
};

//routes.js

var passport = require('passport');

module.exports = function(app) {

    app.get('/login', function(req, res) {
        res.send('login');
    });

    app.post('/login', function(req, res, next) {
        passport.authenticate('local', function(err, user, info) {
            if (err) {
                return next(err);
            }
            if (!user) {
              console.log(user);
              console.log('no user');
                return res.redirect('/login');
            }
            req.logIn(user, function(err) {
                if (err) {
                    return next(err);
                }
                return res.redirect('/');
            });
        })(req, res, next);
    });

//index.js, where i call the auth

require('./src/auth/init')(app);
require('./src/auth/routes')(app);

edit solution the issue was with postman, I hade to change the body post data to x-www-form-urlencoded

about 4 years ago · Santiago Trujillo
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