We have answer of your question!

100% solved queries, no empty question

Question: NodeJS Passport function not getting called


I am trying to make a Facebook login

var passport = require('passport');
var express = require('express');
var FacebookStrategy = require('passport-facebook').Strategy;
var bodyParser = require('body-parser');
var app = express();

passport.use(new FacebookStrategy({
        clientID: '-',
        clientSecret: '-',
        callbackURL: "http://localhost:3000"
    function(accessToken, refreshToken, profile, done) {
        console.log("Token:", accessToken);
        console.log("Refresh token:", refreshToken);

    bodyParser.urlencoded({ extended: true }),

app.get('/', function (req, res) {


But why I never get the console logs from the function inside the FacebookStrategy ? The login works perfectly and I get redirected to the callbackURL but that function looks like it doesn't even get called

Question author User2391356 | Source



You need to initialize passport before using its authentication strategies.

From Passport Documantation itself:

In a Connect or Express-based application, passport.initialize() middleware is required to initialize Passport. If your application uses persistent login sessions, passport.session() middleware must also be used.

Note that enabling session support is entirely optional, though it is recommended for most applications. If enabled, be sure to use express.session() before passport.session() to ensure that the login session is restored in the correct order.

add these lines before passport.use(new FacebookStrategy({...})

app.use(express.session({ secret: 'your_express_session_secret' }));

Go through Passport configure Documentation to understand it better.

Dont forget to import required node modules:

var cookieParser = require('cookie-parser');
var expressSession = require('express-session');

Hope this helps!

Answer author Ravi-shankar

Tickanswer.com is providing the only single recommended solution of the question NodeJS Passport function not getting called under the categories i.e node.js , passport.js , . Our team of experts filter the best solution for you.

Related Search Queries:

passport local strategy not called , passport.authenticate is not a function ,

You may also add your answer

Thanks for contributing an answer to Tick Answer!