JavaScript passport.authenticate is not a function

Hello I am new in NodeJs and I have been following this tutorial http://code.tutsplus.com/tutorials/authenticating-nodejs-applications-with-passport--cms-21619 to create a app with authenticating. I tried to follow all the structre and code from the tutorial (code is on github https://github.com/tutsplus/passport-mongo) but when I open my app in browser i get error this error

TypeError: passport.authenticate is not a function at module.exports (C:\myApp\routes\index.js:24:34)

This is my index.js route file

var express = require('express');
var router = express.Router();
var passport = require('passport');

var isAuthenticated = function (req, res, next) {
  // if user is authenticated in the session, call the next() to call the next request handler
  // Passport adds this method to request object. A middleware is allowed to add properties to
  // request and response objects
  if (req.isAuthenticated())
    return next();
  // if the user is not authenticated then redirect him to the login page
  res.redirect('/');
}

module.exports = function(passport){

  /* GET login page. */
  router.get('/', function(req, res) {
    // Display the Login page with any flash message, if any
    res.render('index', { message: req.flash('message') });
  });

  /* Handle Login POST */
  router.post('/login', passport.authenticate('login', {
    successRedirect: '/home',
    failureRedirect: '/',
    failureFlash : true
  }));

  /* GET Registration Page */
  router.get('/signup', function(req, res){
    res.render('register',{message: req.flash('message')});
  });

  /* Handle Registration POST */
  router.post('/signup', passport.authenticate('signup', {
    successRedirect: '/home',
    failureRedirect: '/signup',
    failureFlash : true
  }));

  /* GET Home Page */
  router.get('/home', isAuthenticated, function(req, res){
    res.render('home', { user: req.user });
  });

  /* Handle Logout */
  router.get('/signout', function(req, res) {
    req.logout();
    res.redirect('/');
  });

  return router;
}

Probabbly the problem is there, maybe routing was change in some version of express, but I cant figure out what is the problem. Can you help pme please ?

Answer:1

I had same problem. Look at app.js. There must be:

var routes = require('./routes/index')(passport);
Answer:2

I am trying to style my <code>/<pre> tags without preventing the user from being able to highlight and copy the code properly. The way I was hoping to do this (see below) only works for ...

I am trying to style my <code>/<pre> tags without preventing the user from being able to highlight and copy the code properly. The way I was hoping to do this (see below) only works for ...

I am doing a request in this way using AngularJS: var config = { headers: { 'Authorization': 'somehash', 'Content-Type': 'application/json; charset=UTF-8' } }; $...

I am doing a request in this way using AngularJS: var config = { headers: { 'Authorization': 'somehash', 'Content-Type': 'application/json; charset=UTF-8' } }; $...

  1. angularjs http request default timeout
  2. angularjs http request timeout
  3. angularjs http request progress bar
  4. angularjs http request in loop
  5. angularjs http request interceptor example
  6. angularjs http request
  7. angularjs http request interceptor
  8. angularjs http request error handling
  9. angularjs http request synchronous
  10. angularjs http request parameters
  11. angularjs http request cors
  12. angularjs http request body
  13. angularjs http request json
  14. angularjs http request multipart/form-data
  15. angularjs http request cross domain
  16. angularjs http request method options
  17. angularjs http request content type
  18. angularjs http request form data
  19. angularjs http request async
  20. angularjs http request cookie

I've got an array var itemsArr = ["blue", "wine", "orange", "yellow", "cyan"]; How can I get a certain amount of array elements from the END to the FRONT of the array? Expected output: example 1: ...

I've got an array var itemsArr = ["blue", "wine", "orange", "yellow", "cyan"]; How can I get a certain amount of array elements from the END to the FRONT of the array? Expected output: example 1: ...

I received Binary Data as String, and how do I convert it to JS Number with little endian CPU? Does ArrayBuffer, DataView useful? It is not just radix converting question. 16 in 2 radix is 10000 not ...

I received Binary Data as String, and how do I convert it to JS Number with little endian CPU? Does ArrayBuffer, DataView useful? It is not just radix converting question. 16 in 2 radix is 10000 not ...

  1. binary number data type
  2. binary number data
  3. data binary number system
  4. binary number data in c
  5. binary number data type sql
  6. binary data to number python
  7. c binary number data type