我正在尝试使用PassportJs with 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 ());
我修好了
答案 0 :(得分:2)
我必须为每个本地策略提供不同的名称 我不得不序列化/反序列化,具体取决于用户的类型(在我的情况下是客户端或管理员)。
答案 1 :(得分:0)
您还想使用单独的护照实例
var Passport = require ('passport');
var passportAdmin = new Passport.Passport();
var passportClient = new Passport.Passport();