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

PassportJS Passport-local-mongoose - multiple local strategies not working #301

Open
prajwalsadaphal opened this issue Mar 13, 2020 · 1 comment

Comments

@prajwalsadaphal
Copy link

I'm developing a nodejs application and a I need two local strategies. The registration of both goes well, the problem is when I try to login with the enterprise user.

Heres is my code:

`let User = require('./models/userModel')
passport.use(User.createStrategy());
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

let Enterprise = require('./models/enterpriseModel')
let EnterpriseStrategy = require('passport-local').Strategy
passport.use('enterprise-local', new EnterpriseStrategy(Enterprise.authenticate()))
passport.serializeUser(Enterprise.serializeUser());
passport.deserializeUser(Enterprise.deserializeUser());

// Refactored code. But returns an error. ReferenceERROR: isUser is not defined
// passport.serializeUser(function(user, done) {
// if (isUser(user)) {
// done(null, User.serializeUser())
// } else if (isEnterprise(user)) {
// done(null, Enterprise.serializeUser())
// }
// });`

Some people told me that the problem is that I'm overriding the serialization. Then I used this commented code. But also return an error. isUser is not defined.

@prajwalsadaphal prajwalsadaphal changed the title PassportJS - multiple local strategies not working PassportJS Passport-local-mongoose - multiple local strategies not working Mar 13, 2020
@kheftel
Copy link
Contributor

kheftel commented Mar 13, 2020

Could you achieve this with a user type variable/flag instead of multiple local strategies? I'm not sure if multiple local strategies are supported or not, just spitballing.

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

2 participants