sails101 / using-passport

How do I use Passport with my Sails app?
67 stars 14 forks source link

Cannot set property 'user' of undefined #5

Open TroutNemesis opened 7 years ago

TroutNemesis commented 7 years ago

TypeError: Cannot set property 'user' of undefined at /Users/matthewlinford/Desktop/Positive_Learning/ell-admin/api/hooks/passport/index.js:160:31 at pass (/Users/matthewlinford/Desktop/Positive_Learning/ell-admin/node_modules/passport/lib/authenticator.js:267:43) at serialized (/Users/matthewlinford/Desktop/Positive_Learning/ell-admin/node_modules/passport/lib/authenticator.js:276:7) at /Users/matthewlinford/Desktop/Positive_Learning/ell-admin/api/hooks/passport/index.js:66:6 at pass (/Users/matthewlinford/Desktop/Positive_Learning/ell-admin/node_modules/passport/lib/authenticator.js:284:9) at Authenticator.serializeUser (/Users/matthewlinford/Desktop/Positive_Learning/ell-admin/node_modules/passport/lib/authenticator.js:289:5) at req.login.req.logIn (/Users/matthewlinford/Desktop/Positive_Learning/ell-admin/api/hooks/passport/index.js:155:26) at afterVerifyingCredentials (/Users/matthewlinford/Desktop/Positive_Learning/ell-admin/api/responses/login.js:119:10) at Strategy.strategy.success (/Users/matthewlinford/Desktop/Positive_Learning/ell-admin/node_modules/passport/lib/middleware/authenticate.js:201:18) at verified (/Users/matthewlinford/Desktop/Positive_Learning/ell-admin/node_modules/passport-local/lib/strategy.js:83:10) at /Users/matthewlinford/Desktop/Positive_Learning/ell-admin/api/responses/login.js:93:12

I get the above error whenever I try to login. I haven't meddled with the hook you wrote. Any ideas on what might be causing this?

sgress454 commented 7 years ago

Hm, that is curious. It looks like the Passport session isn't being initialized. Are you using the default (memory) session store?

TroutNemesis commented 7 years ago

Idk I followed the tutorial/copied the repo pretty exactly. Where does one set the type of memory session?

alinvdu commented 7 years ago

I also get this error regarding _passport.session being undefined. I guess session store should be enabled by default thus session initialization should work. But it doesn't, does anyone know why?

chrislbennett commented 7 years ago

Did anyone figure out a solution to this issue? I'm running into the same thing and not making any headway on it ...

elipeters commented 6 years ago

res.login in the UserController is not constructed properly - commented out are 2 examples of how to properly pass the required User, Object and callback Function to passport/index.js.

In UserController.js CHANGE login: function (req, res) { return res.login({ successRedirect: '/' }); },

TO login: function (req, res) { return req.login({user: req.params.all()}, function(err){ if(err) return res.notFound(null, 'user/signup'); return res.view('/'); }); },

hasnainelahi commented 5 years ago

I need Help 👍 Unhandled rejection TypeError: Cannot set property 'user' of undefined