Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: User is not defined #37

Open
tdesaules opened this issue Jan 22, 2016 · 12 comments
Open

ReferenceError: User is not defined #37

tdesaules opened this issue Jan 22, 2016 · 12 comments

Comments

@tdesaules
Copy link

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
Copy link

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

@ricardo-cantu
Copy link

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

@GeorgeChen1982
Copy link

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

@GeorgeChen1982
Copy link

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
Copy link

dryptm commented May 4, 2020

still it doesnt work!!!!

@JairusSW
Copy link

Seems like User should be defined as a sequelize instance

@yogeshrathod2508
Copy link

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

  • User.find()
    .then((user) => res.json(user),{currPage:"Users"})
    .catch((err) => res.status(400).json("Error is " + err),{currPage:"Users"})

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
Copy link

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
Copy link

@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
Copy link

Nevermind, solved it!

@spydaspider
Copy link

How did you solve it

@sandhyapatel12
Copy link

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

import this line and solve your error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants