dimanche 29 mars 2015

Passport JS has no method 'authenticate'

Node is showing me a weird looking error, and I have been following examples in writing this code but it doesn't work for me. Here is the error.



router.post('/login',passport.authenticate('local',
^

TypeError: Object function (req, res, next) {
app.handle(req, res, next);
} has no method 'authenticate'
at Object.<anonymous> (/Users/Jasim/Documents/WorkArea/nearby-hashtags/routes/auth.js:34:31)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/Jasim/Documents/WorkArea/nearby-hashtags/app.js:63:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
30 Mar 02:11:06 - [nodemon] app crashed - waiting for file changes before starting...


Here is my auth.js



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

router.route('/register')
.get(function(req, res, next)
{
res.render('register', { title: 'Register' });
})
.post(function(req, res, next)
{
User.register(new User({username: req.body.EmailID, email : req.body.EmailID, name: req.body.username}), req.body.Password,
function(err, user)
{
if (err)
{
return res.render('register', { user : user });
}
passport.authenticate('local')(req, res, function ()
{
res.redirect('/home');
});
});
});

router.get('/login',function(req, res, next)
{
res.render('index', {title: 'Login'});
});

router.post('/login',passport.authenticate('local',
{
failureRedirect:'/',
successRedirect:'/home',
failureFlash: true
}), function(req, res, next){});

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

module.exports = router;


Please let me know if more information is required.


Aucun commentaire:

Enregistrer un commentaire