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

128
Views
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
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!