3 var apiClient
= require('../components/api-client');
4 var serviceWorkerDeregistation
= require('gitter-web-service-worker/browser/deregistration');
5 var Promise
= require('bluebird');
6 const appEvents
= require('./appevents');
8 function navigate(href
) {
9 window
.location
.href
= href
;
12 function logout(forcedRedirect
) {
13 // Notify others, that they shouldn't redirect while we are trying to logout
14 // There is not a `account.logout-stop` event because this should always be sucessful in redirecting
15 appEvents
.trigger('account.logout-start');
17 return Promise
.all([apiClient
.web
.post('/logout'), serviceWorkerDeregistation
.uninstall()])
18 .spread(function(response
) {
20 navigate(forcedRedirect
);
21 } else if (response
&& response
.redirect
) {
22 navigate(response
.redirect
);
29 navigate(forcedRedirect
);
36 module
.exports
= logout
;