I have an express app with a user and admin section. Both will run on different ports and need different authentication. I created an app.js where I include passport and create an app as well as adminApp. Then I initialize passport for both as follows:
var passport = require('passport');
var app = express();
var adminapp = express();
adminapp.use(passport.initialize());
adminapp.use(passport.session());
app.use(passport.initialize());
app.use(passport.session());
Now I have routes defined to listen to /auth and handle authentication. Since I am running these on different ports, I have same patterns for routes, and both are listening correctly on their ports. So lets say I have a userSessions.js
and adminSessions.js
files to handle the authentication routes. These are included as follows:
var userSessions = require('./routes/userSessions');
var adminSessions = require('./routes/adminSessions');
app.use('/auth', userSessions);
adminapp.use('/auth', adminSessions);
Now if I try to authenticate on the admin app, it still goes to the passport.serializeUser
and passport.deSerializeUser
methods of userSessions.js
.
How can I handle this situation so that admin and user authentication are handled separately? Or am I doing this the wrong way and admin section should be handled in pletely different app?
I have an express app with a user and admin section. Both will run on different ports and need different authentication. I created an app.js where I include passport and create an app as well as adminApp. Then I initialize passport for both as follows:
var passport = require('passport');
var app = express();
var adminapp = express();
adminapp.use(passport.initialize());
adminapp.use(passport.session());
app.use(passport.initialize());
app.use(passport.session());
Now I have routes defined to listen to /auth and handle authentication. Since I am running these on different ports, I have same patterns for routes, and both are listening correctly on their ports. So lets say I have a userSessions.js
and adminSessions.js
files to handle the authentication routes. These are included as follows:
var userSessions = require('./routes/userSessions');
var adminSessions = require('./routes/adminSessions');
app.use('/auth', userSessions);
adminapp.use('/auth', adminSessions);
Now if I try to authenticate on the admin app, it still goes to the passport.serializeUser
and passport.deSerializeUser
methods of userSessions.js
.
How can I handle this situation so that admin and user authentication are handled separately? Or am I doing this the wrong way and admin section should be handled in pletely different app?
Share Improve this question asked Feb 14, 2016 at 13:25 Vivek V DwivediVivek V Dwivedi 2,6152 gold badges30 silver badges40 bronze badges1 Answer
Reset to default 10Have not tried but you can look for passports
var Passport = require('passport').Passport,
appPass = new Passport(),
adminappPass = new Passport();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742323384a4422265.html
评论列表(0条)