1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-14 00:19:16 +01:00

fix: SimpleAuthentication should work with custom basePaths

This commit is contained in:
ivaosthu 2019-03-03 11:41:56 +01:00 committed by Ivar Conradi Østhus
parent 227c6c2e7a
commit e14d7fc5f0
2 changed files with 6 additions and 6 deletions

View File

@ -39,7 +39,7 @@ module.exports = function(config) {
} }
if (config.adminAuthentication === 'unsecure') { if (config.adminAuthentication === 'unsecure') {
simpleAuthentication(app); simpleAuthentication(baseUriPath, app);
} }
if (typeof config.preRouterHook === 'function') { if (typeof config.preRouterHook === 'function') {

View File

@ -3,8 +3,8 @@
const User = require('../user'); const User = require('../user');
const AuthenticationRequired = require('../authentication-required'); const AuthenticationRequired = require('../authentication-required');
function unsecureAuthentication(app) { function unsecureAuthentication(basePath = '', app) {
app.post('/api/admin/login', (req, res) => { app.post(`${basePath}/api/admin/login`, (req, res) => {
const user = req.body; const user = req.body;
req.session.user = new User({ email: user.email }); req.session.user = new User({ email: user.email });
res.status(200) res.status(200)
@ -12,14 +12,14 @@ function unsecureAuthentication(app) {
.end(); .end();
}); });
app.use('/api/admin/', (req, res, next) => { app.use(`${basePath}/api/admin/`, (req, res, next) => {
if (req.session.user && req.session.user.email) { if (req.session.user && req.session.user.email) {
req.user = req.session.user; req.user = req.session.user;
} }
next(); next();
}); });
app.use('/api/admin/', (req, res, next) => { app.use(`${basePath}/api/admin/`, (req, res, next) => {
if (req.user) { if (req.user) {
next(); next();
} else { } else {
@ -27,7 +27,7 @@ function unsecureAuthentication(app) {
.status('401') .status('401')
.json( .json(
new AuthenticationRequired({ new AuthenticationRequired({
path: '/api/admin/login', path: `${basePath}/api/admin/login`,
type: 'unsecure', type: 'unsecure',
message: message:
'You have to indentify yourself in order to use Unleash.', 'You have to indentify yourself in order to use Unleash.',