我正在尝试使用 PassportJs 和 express 使用多种类型的用户(每个用户都有不同的模型)。当我只对一种类型的用户使用它时,它是可以的,但是当我添加第二个用户时,它就不起作用了。任何想法 ?
// Configuring Passport
var passport = require ('passport');
var LocalStrategyAdmin = require ('passport-local').Strategy;
var LocalStrategyClient = require ('passport-local').Strategy;
var adminModel = require ('./models/adminModel');
var clientModel = require ('./models/clientModel');
var session = require ('cookie-session');
app.use (session ({keys: [secretKey1, secretKey2]}));
app.use (passport.initialize ());
app.use (passport.session ());
passport.use (new LocalStrategyAdmin (adminModel.authenticate ()));
passport.use (new LocalStrategyClient (clientModel.authenticate ()));
passport.serializeUser (adminModel.serializeUser ());
passport.deserializeUser (adminModel.deserializeUser ());
passport.serializeUser (clientModel.serializeUser ());
passport.deserializeUser (clientModel.deserializeUser ());
我修好了它
- 我必须为每个本地策略指定不同的名称
- 我必须根据用户的类型(在我的情况下为客户端或管理员)进行序列化/反序列化。