Skip to content

Commit

Permalink
fix: SimpleAuthentication should work with custom basePaths
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaosthu committed Mar 9, 2019
1 parent 7e0913b commit e0eac6c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/app.js
Expand Up @@ -39,7 +39,7 @@ module.exports = function(config) {
}

if (config.adminAuthentication === 'unsecure') {
simpleAuthentication(app);
simpleAuthentication(baseUriPath, app);
}

if (typeof config.preRouterHook === 'function') {
Expand Down
10 changes: 5 additions & 5 deletions lib/middleware/simple-authentication.js
Expand Up @@ -3,31 +3,31 @@
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)
.json(req.session.user)
.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 {
return res
.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.',
Expand Down

0 comments on commit e0eac6c

Please sign in to comment.