Commit 996e13b3 by Johannes Zellner

Fix logout situation if token is invalid

1 parent c66d7093
Showing with 16 additions and 9 deletions
(function () { (function () {
'use strict'; 'use strict';
/* global superagent */
/* global Vue */
/* global $ */
/* global filesize */
// poor man's async // poor man's async
function asyncForEach(items, handler, callback) { function asyncForEach(items, handler, callback) {
var cur = 0; var cur = 0;
...@@ -86,6 +91,16 @@ function refresh() { ...@@ -86,6 +91,16 @@ function refresh() {
loadDirectory(app.path); loadDirectory(app.path);
} }
function logout() {
superagent.post('/api/logout').query({ access_token: localStorage.accessToken }).end(function (error) {
if (error) console.error(error);
app.session.valid = false;
delete localStorage.accessToken;
});
}
function loadDirectory(filePath) { function loadDirectory(filePath) {
app.busy = true; app.busy = true;
...@@ -278,8 +293,6 @@ var app = new Vue({ ...@@ -278,8 +293,6 @@ var app = new Vue({
}); });
}, },
onOptionsMenu: function (command) { onOptionsMenu: function (command) {
var that = this;
if (command === 'folderListing') { if (command === 'folderListing') {
superagent.put('/api/settings').send({ folderListingEnabled: this.folderListingEnabled }).query({ access_token: localStorage.accessToken }).end(function (error) { superagent.put('/api/settings').send({ folderListingEnabled: this.folderListingEnabled }).query({ access_token: localStorage.accessToken }).end(function (error) {
if (error) console.error(error); if (error) console.error(error);
...@@ -295,13 +308,7 @@ var app = new Vue({ ...@@ -295,13 +308,7 @@ var app = new Vue({
center: true center: true
}).then(function () {}).catch(function () {}); }).then(function () {}).catch(function () {});
} else if (command === 'logout') { } else if (command === 'logout') {
superagent.post('/api/logout').query({ access_token: localStorage.accessToken }).end(function (error) { logout();
if (error) console.error(error);
that.session.valid = false;
delete localStorage.accessToken;
});
} }
}, },
onDownload: function (entry) { onDownload: function (entry) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!