Вы можете сделать это, добавив опцию if-else
в промежуточное ПО, следующий пример может вам помочь
login = basic(function (challenge, callback) {
if (challenge.username === 'user' && challenge.password === 'test') {
callback(null, true, {
admin: false
});
} else if (challenge.username === 'admin' && challenge.password === 'test') {
callback(null, true, {
admin: true
});
} else {
callback(null, false, {
error: 'INVALID_PASSWORD'
});
}
});
app.use(login); //middleware
app.use('/', routes);
app.use('/details', detailsRoutes);
и в маршрутах,
if (req.authenticated && req.authentication.admin) {
// send all tabs as this user is admin
} else if (req.authenticated) {
// send limited tabs as user is not admin
} else {
res.status(401).send();
}