From e09833fab85c1f36adcf9e035616719e6611c004 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Thu, 21 Apr 2016 01:17:57 +0200 Subject: [PATCH] Improve refresh auth --- public/script.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/public/script.js b/public/script.js index 4cb6ae0..58392d3 100644 --- a/public/script.js +++ b/public/script.js @@ -240,23 +240,17 @@ var App = React.createClass({ return !(this.state.access_token == null && this.state.refresh_token == null); }, refreshAuth: function (access, refresh) { - if (access == null && refresh == null) { - this.setState({ - access_token: access, - refresh_token: refresh, - playlists: null - }); - } - else { - this.setState({ - access_token: access, - refresh_token: refresh - }); + this.setState({ + access_token: access, + refresh_token: refresh + }); + + if (!(access == null && refresh == null)) { this.getPlaylists(); } }, componentDidMount: function () { - if (this.state.access_token) { + if (this.isLoggedIn()) { this.getPlaylists(); } }, @@ -265,10 +259,10 @@ var App = React.createClass({ access_token: this.state.access_token, refresh_token: this.state.refresh_token }; - var content =

Please log in with Spotify :)

+ var content =

Please log in with Spotify :)

; if (this.isLoggedIn()) { content = ( - + ); }