You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
prajwalsadaphal
changed the title
PassportJS - multiple local strategies not working
PassportJS Passport-local-mongoose - multiple local strategies not working
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.
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.
The text was updated successfully, but these errors were encountered: