diff options
author | Johannes Zellner <johannes@cloudron.io> | 2019-08-06 16:21:26 +0200 |
---|---|---|
committer | Johannes Zellner <johannes@cloudron.io> | 2019-08-06 16:21:26 +0200 |
commit | 34adfa8518ba0b57d1837db1847a13215f31a83c (patch) | |
tree | 3c500b494b0350b35cb8a0748f343fd05c0b4b5e /frontend | |
parent | f384014e30d095a47ddce214a05c860a7c4d6679 (diff) | |
download | Surfer-34adfa8518ba0b57d1837db1847a13215f31a83c.tar.gz Surfer-34adfa8518ba0b57d1837db1847a13215f31a83c.tar.zst Surfer-34adfa8518ba0b57d1837db1847a13215f31a83c.zip |
Replace passport usage with simpler custom middleware
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/js/app.js | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/frontend/js/app.js b/frontend/js/app.js index 9a6251b..d99a840 100644 --- a/frontend/js/app.js +++ b/frontend/js/app.js | |||
@@ -23,14 +23,14 @@ function asyncForEach(items, handler, callback) { | |||
23 | })(); | 23 | })(); |
24 | } | 24 | } |
25 | 25 | ||
26 | function getProfile(accessToken, callback) { | 26 | function initWithToken(accessToken) { |
27 | superagent.get('/api/profile').query({ access_token: accessToken }).end(function (error, result) { | 27 | superagent.get('/api/profile').query({ access_token: accessToken }).end(function (error, result) { |
28 | app.ready = true; | 28 | app.ready = true; |
29 | 29 | ||
30 | if (error && !error.response) return callback(error); | 30 | if (error && !error.response) return console.error(error); |
31 | if (result.statusCode !== 200) { | 31 | if (result.statusCode !== 200) { |
32 | delete localStorage.accessToken; | 32 | delete localStorage.accessToken; |
33 | return callback('Invalid access token'); | 33 | return; |
34 | } | 34 | } |
35 | 35 | ||
36 | localStorage.accessToken = accessToken; | 36 | localStorage.accessToken = accessToken; |
@@ -42,7 +42,7 @@ function getProfile(accessToken, callback) { | |||
42 | 42 | ||
43 | app.folderListingEnabled = !!result.body.folderListingEnabled; | 43 | app.folderListingEnabled = !!result.body.folderListingEnabled; |
44 | 44 | ||
45 | callback(); | 45 | loadDirectory(decode(window.location.hash.slice(1))); |
46 | }); | 46 | }); |
47 | }); | 47 | }); |
48 | } | 48 | } |
@@ -292,11 +292,7 @@ var app = new Vue({ | |||
292 | if (error && !result) return that.$message.error(error.message); | 292 | if (error && !result) return that.$message.error(error.message); |
293 | if (result.statusCode === 401) return that.$message.error('Wrong username or password'); | 293 | if (result.statusCode === 401) return that.$message.error('Wrong username or password'); |
294 | 294 | ||
295 | getProfile(result.body.accessToken, function (error) { | 295 | initWithToken(result.body.accessToken); |
296 | if (error) return console.error(error); | ||
297 | |||
298 | loadDirectory(decode(window.location.hash.slice(1))); | ||
299 | }); | ||
300 | }); | 296 | }); |
301 | }, | 297 | }, |
302 | onOptionsMenu: function (command) { | 298 | onOptionsMenu: function (command) { |
@@ -452,11 +448,7 @@ var app = new Vue({ | |||
452 | } | 448 | } |
453 | }); | 449 | }); |
454 | 450 | ||
455 | getProfile(localStorage.accessToken, function (error) { | 451 | initWithToken(localStorage.accessToken); |
456 | if (error) return console.error(error); | ||
457 | |||
458 | loadDirectory(decode(window.location.hash.slice(1))); | ||
459 | }); | ||
460 | 452 | ||
461 | $(window).on('hashchange', function () { | 453 | $(window).on('hashchange', function () { |
462 | loadDirectory(decode(window.location.hash.slice(1))); | 454 | loadDirectory(decode(window.location.hash.slice(1))); |