Discussion:
[nodejs] passport.js "Cannot read property 'isAuthenticated' of undefined"
Robert Balu
2018-07-21 11:51:36 UTC
Permalink
I've read this answer and applied the solution but still not
working https://stackoverflow.com/questions/29838952/how-to-fix-typeerror-cannot-read-property-authenticate-of-undefined-passportj
routes.js


1. module.exports = function(app, passport) {
2. .......
3. };
4.
5. // route middleware to ensure user is logged in
6. function isLoggedIn(req, res, next) {
7. if (req.isAuthenticated()){
8. return next();
9. }
10. else{
11. alert("not authernticated");
12. }
13. res.redirect('/');
14. }



server.js


1. var express = require('express');
2. var app = express();
3. var port = process.env.PORT || 8080;
4. var mongoose = require('mongoose');
5. var passport = require('passport');
6. var flash = require('connect-flash');
7. .......
8. require('./config/passport')(passport); // pass passport for
configuration
9. .....
10. // required for passport
11. app.use(session({
12. secret: 'ilovescotchscotchyscotchscotch', // session secret
13. resave: true,
14. saveUninitialized: true
15. }));
16. app.use(passport.initialize());
17. app.use(passport.session()); // persistent login sessions
18. app.use(flash()); // use connect-flash for flash messages stored in
session
19.
20. // routes
======================================================================
21. require('./app/routes.js')(app, passport); // load our routes and
pass in our app and fully configured passport
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/6bb5b62f-5629-4884-b88b-698ccca81671%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...