From 268e9ce5042cc89707204153b64f04f1c1b9e0e0 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 19 Jun 2019 23:11:39 -0400 Subject: [PATCH 1/4] make sure to clear old token when logout --- src/lib/persisted_state.js | 3 ++- src/modules/oauth.js | 4 ++++ src/modules/users.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/persisted_state.js b/src/lib/persisted_state.js index 7ab89c12..cad7ea25 100644 --- a/src/lib/persisted_state.js +++ b/src/lib/persisted_state.js @@ -19,7 +19,8 @@ const saveImmedeatelyActions = [ 'setHighlight', 'setOption', 'setClientData', - 'setToken' + 'setToken', + 'clearToken' ] const defaultStorage = (() => { diff --git a/src/modules/oauth.js b/src/modules/oauth.js index 11cb10fe..b7755b64 100644 --- a/src/modules/oauth.js +++ b/src/modules/oauth.js @@ -22,6 +22,10 @@ const oauth = { }, setToken (state, token) { state.userToken = token + }, + clearToken (state) { + state.userToken = false + state.token = false } }, getters: { diff --git a/src/modules/users.js b/src/modules/users.js index 22340271..1e0b16f5 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -399,7 +399,7 @@ const users = { logout (store) { store.commit('clearCurrentUser') store.dispatch('disconnectFromChat') - store.commit('setToken', false) + store.commit('clearToken') store.dispatch('stopFetching', 'friends') store.commit('setBackendInteractor', backendInteractorService(store.getters.getToken())) store.dispatch('stopFetching', 'notifications') From c23228f1967547e7df1462efa7b3bcc1a9a96319 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 19 Jun 2019 23:12:25 -0400 Subject: [PATCH 2/4] fix error breaking logout flow --- src/modules/chat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/chat.js b/src/modules/chat.js index 2804e577..4d8d6699 100644 --- a/src/modules/chat.js +++ b/src/modules/chat.js @@ -21,7 +21,7 @@ const chat = { }, actions: { disconnectFromChat (store) { - store.state.socket.disconnect() + store.state.socket && store.state.socket.disconnect() }, initializeChat (store, socket) { const channel = socket.channel('chat:public') From 8a32731e4d3772e79b3de35185de3454663be52d Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 19 Jun 2019 23:20:14 -0400 Subject: [PATCH 3/4] use clientSecret in login flow --- src/components/login_form/login_form.js | 3 ++- src/components/oauth_callback/oauth_callback.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/login_form/login_form.js b/src/components/login_form/login_form.js index 93214646..4a5b1965 100644 --- a/src/components/login_form/login_form.js +++ b/src/components/login_form/login_form.js @@ -26,9 +26,10 @@ const LoginForm = { this.isTokenAuth ? this.submitToken() : this.submitPassword() }, submitToken () { - const { clientId } = this.oauth + const { clientId, clientSecret } = this.oauth const data = { clientId, + clientSecret, instance: this.instance.server, commit: this.$store.commit } diff --git a/src/components/oauth_callback/oauth_callback.js b/src/components/oauth_callback/oauth_callback.js index 2c6ca235..a3c7b7f9 100644 --- a/src/components/oauth_callback/oauth_callback.js +++ b/src/components/oauth_callback/oauth_callback.js @@ -4,10 +4,11 @@ const oac = { props: ['code'], mounted () { if (this.code) { - const { clientId } = this.$store.state.oauth + const { clientId, clientSecret } = this.$store.state.oauth oauth.getToken({ clientId, + clientSecret, instance: this.$store.state.instance.server, code: this.code }).then((result) => { From bd377148ade7aaf26652dc14ee77683b7e6c8c5a Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 20 Jun 2019 11:47:33 -0400 Subject: [PATCH 4/4] delete state.token instead of setting false --- src/modules/oauth.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/oauth.js b/src/modules/oauth.js index b7755b64..a2a83450 100644 --- a/src/modules/oauth.js +++ b/src/modules/oauth.js @@ -1,3 +1,5 @@ +import { delete as del } from 'vue' + const oauth = { state: { clientId: false, @@ -25,7 +27,9 @@ const oauth = { }, clearToken (state) { state.userToken = false - state.token = false + // state.token is userToken with older name, coming from persistent state + // let's clear it as well, since it is being used as a fallback of state.userToken + del(state, 'token') } }, getters: {