mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-20 05:27:37 +01:00
if there is an error in logout hooks don't crash send error back instead of building 500 page
32 lines
739 B
JavaScript
32 lines
739 B
JavaScript
'use strict';
|
|
|
|
define('logout', ['hooks', 'alerts'], function (hooks, alerts) {
|
|
return function logout(redirect) {
|
|
redirect = redirect === undefined ? true : redirect;
|
|
hooks.fire('action:app.logout');
|
|
|
|
$.ajax(config.relative_path + '/logout', {
|
|
type: 'POST',
|
|
headers: {
|
|
'x-csrf-token': config.csrf_token,
|
|
},
|
|
beforeSend: function () {
|
|
app.flags._logout = true;
|
|
},
|
|
success: function (data) {
|
|
hooks.fire('action:app.loggedOut', data);
|
|
if (redirect) {
|
|
if (data.next) {
|
|
window.location.href = data.next;
|
|
} else {
|
|
window.location.reload();
|
|
}
|
|
}
|
|
},
|
|
error: function (jqXHR) {
|
|
alerts.error(String(jqXHR.responseText || '[[error:logout-error]]'));
|
|
},
|
|
});
|
|
};
|
|
});
|