1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: Logout should not be xhr call (#576)

closes #520
This commit is contained in:
Ivar Conradi Østhus 2020-03-29 22:22:19 +02:00 committed by GitHub
parent 609142f47e
commit 333601eaea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 2 deletions

View File

@ -26,6 +26,7 @@ class UserController extends Controller {
}
}
// Depcreated, use "/logout" instead. Will be removed in later release.
logout(req, res) {
if (req.session) {
req.session = null;
@ -33,7 +34,7 @@ class UserController extends Controller {
if (req.logout) {
req.logout();
}
res.redirect('/');
res.redirect(`${this.config.baseUriPath}/`);
}
}

View File

@ -55,5 +55,5 @@ test('should logout and redirect', t => {
return request
.get(`${base}/api/admin/user/logout`)
.expect(302)
.expect('Location', '/');
.expect('Location', `${base}/`);
});

View File

@ -7,6 +7,7 @@ const FeatureController = require('./client-api/feature.js');
const Controller = require('./controller');
const HealthCheckController = require('./health-check');
const BackstageCTR = require('./backstage.js');
const LogoutController = require('./logout');
const api = require('./api-def');
class IndexRouter extends Controller {
@ -14,6 +15,7 @@ class IndexRouter extends Controller {
super();
this.use('/health', new HealthCheckController(config).router);
this.use('/internal-backstage', new BackstageCTR(config).router);
this.use('/logout', new LogoutController(config).router);
this.get(api.uri, this.index);
this.use(api.links.admin.uri, new AdminApi(config).router);
this.use(api.links.client.uri, new ClientApi(config).router);

22
lib/routes/logout.js Normal file
View File

@ -0,0 +1,22 @@
'use strict';
const Controller = require('./controller');
class HealthCheckController extends Controller {
constructor(config) {
super(config);
this.get('/', this.logout);
}
logout(req, res) {
if (req.session) {
req.session = null;
}
if (req.logout) {
req.logout();
}
res.redirect(`${this.config.baseUriPath}/`);
}
}
module.exports = HealthCheckController;

46
lib/routes/logout.test.js Normal file
View File

@ -0,0 +1,46 @@
'use strict';
const test = require('ava');
const supertest = require('supertest');
const store = require('./../../test/fixtures/store');
const getLogger = require('../../test/fixtures/no-logger');
const getApp = require('../app');
const User = require('../user');
const { EventEmitter } = require('events');
const eventBus = new EventEmitter();
const currentUser = new User({ email: 'test@mail.com' });
function getSetup() {
const base = `/random${Math.round(Math.random() * 1000)}`;
const stores = store.createStores();
const app = getApp({
baseUriPath: base,
stores,
eventBus,
getLogger,
preHook: a => {
a.use((req, res, next) => {
req.user = currentUser;
next();
});
},
});
return {
base,
strategyStore: stores.strategyStore,
request: supertest(app),
};
}
test('should logout and redirect', t => {
t.plan(0);
const { request, base } = getSetup();
return request
.get(`${base}/logout`)
.expect(302)
.expect('Location', `${base}/`);
});