I'm trying to automatically log in a user with PassportJS.
This is my current code:
myRouter.get('/signin', function* (next) {
user = {...};
var res = this.res; // needed for the function below
this.req.login(user, function(err) {
if (err)
console.log('error logging in user - '+err);
return res.redirect('/'); // <--- line 439
});
});
But when I run it, I get the error:
error logging in user - TypeError: undefined is not a function
TypeError: undefined is not a function
at /srv/www/domain.com/app.js:439:32
at /srv/www/domain.com/node_modules/koa-passport/node_modules/passport/lib/http/request.js:49:48
at pass (/srv/www/domain.com/node_modules/koa-passport/node_modules/passport/lib/authenticator.js:293:14)
at Authenticator.serializeUser (/srv/www/domain.com/node_modules/koa-passport/node_modules/passport/lib/authenticator.js:295:5)
at Object.req.login.req.logIn (/srv/www/domain.com/node_modules/koa-passport/node_modules/passport/lib/http/request.js:48:29)
at Object.<anonymous> (/srv/www/domain.com/app.js:434:26)
at GeneratorFunctionPrototype.next (native)
at Object.dispatch (/srv/www/domain.com/node_modules/koa-router/lib/router.js:317:14)
at GeneratorFunctionPrototype.next (native)
at Object.<anonymous> (/srv/www/domain.com/node_modules/koa-common/node_modules/koa-mount/index.js:56:23)