auth0 / passport-windowsauth

Windows Authentication strategy for Passport.js
MIT License
179 stars 51 forks source link

ReferenceError: User is not defined #37

Open tdesaules opened 8 years ago

tdesaules commented 8 years ago

Hi guys,

I test the most simple :

passport.use(new WindowsStrategy({ integrated: true }, function(profile, done){ User.findOrCreate({ waId: profile.id }, function (err, user) { done(err, user); }); }));

app.get('/windows', passport.authenticate('WindowsAuthentication'), function (req, res){ res.redirect('/foo/bar'); });

But I always get : ReferenceError: User is not defined at Strategy._verify (C:\inetpub\wwwroot\auth\server.js:48:5) at Strategy.authenticate (C:\inetpub\wwwroot\auth\node_modules\passport-windowsauth\lib\strategy.js:163:12) at attempt (C:\inetpub\wwwroot\auth\node_modules\passport\lib\middleware\authenticate.js:348:16) at authenticate (C:\inetpub\wwwroot\auth\node_modules\passport\lib\middleware\authenticate.js:349:7) at Layer.handle as handle_request at next (C:\inetpub\wwwroot\auth\node_modules\express\lib\router\route.js:131:13) at Route.dispatch (C:\inetpub\wwwroot\auth\node_modules\express\lib\router\route.js:112:3) at Layer.handle as handle_request at C:\inetpub\wwwroot\auth\node_modules\express\lib\router\index.js:277:22 at Function.process_params (C:\inetpub\wwwroot\auth\node_modules\express\lib\router\index.js:330:12) at next (C:\inetpub\wwwroot\auth\node_modules\express\lib\router\index.js:271:10) at SessionStrategy.strategy.pass (C:\inetpub\wwwroot\auth\node_modules\passport\lib\middleware\authenticate.js:325:9) at SessionStrategy.authenticate (C:\inetpub\wwwroot\auth\node_modules\passport\lib\strategies\session.js:71:10) at attempt (C:\inetpub\wwwroot\auth\node_modules\passport\lib\middleware\authenticate.js:348:16) at authenticate (C:\inetpub\wwwroot\auth\node_modules\passport\lib\middleware\authenticate.js:349:7) at Layer.handle as handle_request

Any idea ?

ricardo-cantu commented 8 years ago

Any updates on this? I'm getting the same.

ricardo-cantu commented 8 years ago

Turns out User.* is just an example of user code, it's not anything included by this module.

GeorgeChen1982 commented 7 years ago

yes, I am facing the same situation, what should I do?

GeorgeChen1982 commented 7 years ago

I have figured out what went wrong. 'User' is a something like database or a object mapper and is not provided by passport module. Actually, you don't need it. I replace the snippet just like the following:

old:

User.findOrCreate({ waId: profile.id }, function (err, user) { done(err, user); });

new:

if (profile) { user = profile; return done(null, user); } else { return done(null, false); }

dryptm commented 4 years ago

still it doesnt work!!!!

JairusSW commented 4 years ago

Seems like User should be defined as a sequelize instance

yogeshrathod2508 commented 3 years ago

From both points we can see that the variable to require the model file should be used in find() method This solved my problem. Hope it solves yours

raginiagrawal02 commented 2 years ago

still it doesnt work!!!!

add this serializer if you are not getting the error - "Failed to serialize user into session"

passport.serializeUser(function(user, done) { done(null, user.id); });

formulaRoot commented 2 years ago

@raginiagrawal02 I have that and my code is not working. But, I also have the following: passport.deserializeUser(function(user, done){ User.findById(id, function(err, user) { done(err, user); }); });

formulaRoot commented 2 years ago

Nevermind, solved it!

spydaspider commented 1 year ago

How did you solve it

sandhyapatel12 commented 5 months ago

const User = require('../models/User')

import this line and solve your error