Open tdesaules opened 8 years ago
Any updates on this? I'm getting the same.
Turns out User.* is just an example of user code, it's not anything included by this module.
yes, I am facing the same situation, what should I do?
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:
User.findOrCreate({ waId: profile.id }, function (err, user) { done(err, user); });
if (profile) { user = profile; return done(null, user); } else { return done(null, false); }
still it doesnt work!!!!
Seems like User should be defined as a sequelize instance
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
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); });
@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); }); });
Nevermind, solved it!
How did you solve it
const User = require('../models/User')
import this line and solve your error
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 ?