Merge branch 'hotfix/21.56.9' into master
[gitter.git] / public / js / utils / logout.js
blob9099aede250b8a76ab3cd7aa766c70c170fe5409
1 'use strict';
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) {
19 if (forcedRedirect) {
20 navigate(forcedRedirect);
21 } else if (response && response.redirect) {
22 navigate(response.redirect);
23 } else {
24 navigate('/');
27 .catch(function() {
28 if (forcedRedirect) {
29 navigate(forcedRedirect);
30 } else {
31 navigate('/');
33 });
36 module.exports = logout;