From 996e13b351ddcc106e4700adc6257d0815e2cd23 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Mon, 8 Oct 2018 16:09:42 +0200 Subject: Fix logout situation if token is invalid --- frontend/js/app.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'frontend') diff --git a/frontend/js/app.js b/frontend/js/app.js index be5705f..0a6ada1 100644 --- a/frontend/js/app.js +++ b/frontend/js/app.js @@ -1,6 +1,11 @@ (function () { 'use strict'; +/* global superagent */ +/* global Vue */ +/* global $ */ +/* global filesize */ + // poor man's async function asyncForEach(items, handler, callback) { var cur = 0; @@ -86,6 +91,16 @@ function refresh() { 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) { app.busy = true; @@ -278,8 +293,6 @@ var app = new Vue({ }); }, onOptionsMenu: function (command) { - var that = this; - if (command === 'folderListing') { superagent.put('/api/settings').send({ folderListingEnabled: this.folderListingEnabled }).query({ access_token: localStorage.accessToken }).end(function (error) { if (error) console.error(error); @@ -295,13 +308,7 @@ var app = new Vue({ center: true }).then(function () {}).catch(function () {}); } else if (command === 'logout') { - superagent.post('/api/logout').query({ access_token: localStorage.accessToken }).end(function (error) { - if (error) console.error(error); - - that.session.valid = false; - - delete localStorage.accessToken; - }); + logout(); } }, onDownload: function (entry) { -- cgit v1.2.3