mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
fix: SimpleAuthentication should work with custom basePaths
This commit is contained in:
parent
227c6c2e7a
commit
e14d7fc5f0
@ -39,7 +39,7 @@ module.exports = function(config) {
|
||||
}
|
||||
|
||||
if (config.adminAuthentication === 'unsecure') {
|
||||
simpleAuthentication(app);
|
||||
simpleAuthentication(baseUriPath, app);
|
||||
}
|
||||
|
||||
if (typeof config.preRouterHook === 'function') {
|
||||
|
@ -3,8 +3,8 @@
|
||||
const User = require('../user');
|
||||
const AuthenticationRequired = require('../authentication-required');
|
||||
|
||||
function unsecureAuthentication(app) {
|
||||
app.post('/api/admin/login', (req, res) => {
|
||||
function unsecureAuthentication(basePath = '', app) {
|
||||
app.post(`${basePath}/api/admin/login`, (req, res) => {
|
||||
const user = req.body;
|
||||
req.session.user = new User({ email: user.email });
|
||||
res.status(200)
|
||||
@ -12,14 +12,14 @@ function unsecureAuthentication(app) {
|
||||
.end();
|
||||
});
|
||||
|
||||
app.use('/api/admin/', (req, res, next) => {
|
||||
app.use(`${basePath}/api/admin/`, (req, res, next) => {
|
||||
if (req.session.user && req.session.user.email) {
|
||||
req.user = req.session.user;
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
app.use('/api/admin/', (req, res, next) => {
|
||||
app.use(`${basePath}/api/admin/`, (req, res, next) => {
|
||||
if (req.user) {
|
||||
next();
|
||||
} else {
|
||||
@ -27,7 +27,7 @@ function unsecureAuthentication(app) {
|
||||
.status('401')
|
||||
.json(
|
||||
new AuthenticationRequired({
|
||||
path: '/api/admin/login',
|
||||
path: `${basePath}/api/admin/login`,
|
||||
type: 'unsecure',
|
||||
message:
|
||||
'You have to indentify yourself in order to use Unleash.',
|
||||
|
Loading…
Reference in New Issue
Block a user