diff --git a/changes/changelog.d/124.bugfix b/changes/changelog.d/124.bugfix new file mode 100644 index 0000000000000000000000000000000000000000..b1e104a438b776a035818bb0bf440dc6d7caa5f8 --- /dev/null +++ b/changes/changelog.d/124.bugfix @@ -0,0 +1 @@ +Reset all sensitive front-end data on logout (#124) diff --git a/changes/changelog.d/155.bugfix b/changes/changelog.d/155.bugfix new file mode 100644 index 0000000000000000000000000000000000000000..2252d56d7d2a0c5db5735cc8d00195746ab5b772 --- /dev/null +++ b/changes/changelog.d/155.bugfix @@ -0,0 +1 @@ +Fixed broken playlist modal after login (#155) diff --git a/front/src/components/Sidebar.vue b/front/src/components/Sidebar.vue index 45487b6fbe7d1d26643bd12d7fc6e5f8e69c84ff..33cf1fd49e51cad5ab42ebdf6494ad60e4a3aca7 100644 --- a/front/src/components/Sidebar.vue +++ b/front/src/components/Sidebar.vue @@ -35,7 +35,7 @@ <router-link class="item" v-if="$store.state.auth.authenticated" :to="{name: 'logout'}"><i class="sign out icon"></i> Logout</router-link> <router-link class="item" v-else :to="{name: 'login'}"><i class="sign in icon"></i> Login</router-link> <router-link class="item" :to="{path: '/library'}"><i class="sound icon"> </i>Browse library</router-link> - <router-link class="item" :to="{path: '/favorites'}"><i class="heart icon"></i> Favorites</router-link> + <router-link class="item" v-if="$store.state.auth.authenticated" :to="{path: '/favorites'}"><i class="heart icon"></i> Favorites</router-link> <a @click="$store.commit('playlists/chooseTrack', null)" v-if="$store.state.auth.authenticated" diff --git a/front/src/store/auth.js b/front/src/store/auth.js index e72e1968f52f1ca3593abfbbdabf4e06fda7b1d5..b1753404f9be65c2d5fe2a067607d83ef45d4d6a 100644 --- a/front/src/store/auth.js +++ b/front/src/store/auth.js @@ -19,6 +19,14 @@ export default { } }, mutations: { + reset (state) { + state.authenticated = false + state.profile = null + state.username = '' + state.token = '' + state.tokenData = {} + state.availablePermissions = {} + }, profile: (state, value) => { state.profile = value }, @@ -53,8 +61,6 @@ export default { return axios.post('token/', credentials).then(response => { logger.default.info('Successfully logged in as', credentials.username) commit('token', response.data.token) - commit('username', credentials.username) - commit('authenticated', true) dispatch('fetchProfile') // Redirect to a specified route router.push(next) @@ -64,19 +70,25 @@ export default { }) }, logout ({commit}) { - commit('authenticated', false) + let modules = [ + 'auth', + 'favorites', + 'player', + 'playlists', + 'queue', + 'radios' + ] + modules.forEach(m => { + commit(`${m}/reset`, null, {root: true}) + }) logger.default.info('Log out, goodbye!') router.push({name: 'index'}) }, check ({commit, dispatch, state}) { logger.default.info('Checking authentication...') var jwt = state.token - var username = state.username if (jwt) { - commit('authenticated', true) - commit('username', username) commit('token', jwt) - logger.default.info('Logged back in as ' + username) dispatch('fetchProfile') dispatch('refreshToken') } else { @@ -88,6 +100,7 @@ export default { return axios.get('users/users/me/').then((response) => { logger.default.info('Successfully fetched user profile') let data = response.data + commit('authenticated', true) commit('profile', data) commit('username', data.username) dispatch('favorites/fetch', null, {root: true}) diff --git a/front/src/store/favorites.js b/front/src/store/favorites.js index a4f85b235daa36567f16528d8396d259e63b1db0..b7e789511217726e74412591d18233e6d25ed762 100644 --- a/front/src/store/favorites.js +++ b/front/src/store/favorites.js @@ -20,6 +20,10 @@ export default { } } state.count = state.tracks.length + }, + reset (state) { + state.tracks = [] + state.count = 0 } }, getters: { diff --git a/front/src/store/player.js b/front/src/store/player.js index d849b7b56ceaa80fa93ab30cd2b5654fbcc33a9f..ed437c3f0220d84ed26693c94a8036c38c756b64 100644 --- a/front/src/store/player.js +++ b/front/src/store/player.js @@ -15,6 +15,10 @@ export default { looping: 0 // 0 -> no, 1 -> on track, 2 -> on queue }, mutations: { + reset (state) { + state.errorCount = 0 + state.playing = false + }, volume (state, value) { value = parseFloat(value) value = Math.min(value, 1) diff --git a/front/src/store/playlists.js b/front/src/store/playlists.js index b3ed3ab235bf09456a4b7cc9d7129963443488ca..d0e144d803eec7917ea67ebc486f1f95c29e8e83 100644 --- a/front/src/store/playlists.js +++ b/front/src/store/playlists.js @@ -17,6 +17,11 @@ export default { }, showModal (state, value) { state.showModal = value + }, + reset (state) { + state.playlists = [] + state.modalTrack = null + state.showModal = false } }, actions: { diff --git a/front/src/store/queue.js b/front/src/store/queue.js index 6a26fa1e9a0dc70609b0ea6fcba6e5b11745f277..2890dd1e8f89ad8f83629499b225dae020ae579d 100644 --- a/front/src/store/queue.js +++ b/front/src/store/queue.js @@ -10,6 +10,12 @@ export default { previousQueue: null }, mutations: { + reset (state) { + state.tracks = [] + state.currentIndex = -1 + state.ended = true + state.previousQueue = null + }, currentIndex (state, value) { state.currentIndex = value }, diff --git a/front/src/store/radios.js b/front/src/store/radios.js index e95db512643d297fa08ecca16df30e8004739e7c..49bbd4f9410dff015721f57073c4d95c58d7146a 100644 --- a/front/src/store/radios.js +++ b/front/src/store/radios.js @@ -26,6 +26,10 @@ export default { } }, mutations: { + reset (state) { + state.running = false + state.current = false + }, current: (state, value) => { state.current = value }, diff --git a/front/test/unit/specs/store/auth.spec.js b/front/test/unit/specs/store/auth.spec.js index 518dc10d4db29f680567d6c996853086cd6b4516..6b187f5c63f7019546214f10c0f59982fcbc60dc 100644 --- a/front/test/unit/specs/store/auth.spec.js +++ b/front/test/unit/specs/store/auth.spec.js @@ -89,7 +89,12 @@ describe('store/auth', () => { action: store.actions.logout, params: {state: {}}, expectedMutations: [ - { type: 'authenticated', payload: false } + { type: 'auth/reset', payload: null, options: {root: true} }, + { type: 'favorites/reset', payload: null, options: {root: true} }, + { type: 'player/reset', payload: null, options: {root: true} }, + { type: 'playlists/reset', payload: null, options: {root: true} }, + { type: 'queue/reset', payload: null, options: {root: true} }, + { type: 'radios/reset', payload: null, options: {root: true} } ] }, done) }) @@ -107,8 +112,6 @@ describe('store/auth', () => { action: store.actions.check, params: {state: {token: 'test', username: 'user'}}, expectedMutations: [ - { type: 'authenticated', payload: true }, - { type: 'username', payload: 'user' }, { type: 'token', payload: 'test' } ], expectedActions: [ @@ -132,8 +135,6 @@ describe('store/auth', () => { payload: {credentials: credentials}, expectedMutations: [ { type: 'token', payload: 'test' }, - { type: 'username', payload: 'bob' }, - { type: 'authenticated', payload: true } ], expectedActions: [ { type: 'fetchProfile' } @@ -175,6 +176,7 @@ describe('store/auth', () => { testAction({ action: store.actions.fetchProfile, expectedMutations: [ + { type: 'authenticated', payload: true }, { type: 'profile', payload: profile }, { type: 'username', payload: profile.username }, { type: 'permission', payload: {key: 'admin', status: true} } diff --git a/front/test/unit/specs/store/queue.spec.js b/front/test/unit/specs/store/queue.spec.js index 2bc5cde4efec16a0cfdcf40ce36b1385780b93a1..5304d1d75ecf47eef6872907ae0728c071538f13 100644 --- a/front/test/unit/specs/store/queue.spec.js +++ b/front/test/unit/specs/store/queue.spec.js @@ -326,7 +326,7 @@ describe('store/queue', () => { action: store.actions.shuffle, params: {state: {currentIndex: 1, tracks: tracks}}, expectedMutations: [ - { type: 'player/currentTime', payload: 0 , options: {root: true}}, + { type: 'player/currentTime', payload: 0, options: {root: true}}, { type: 'tracks', payload: [] } ], expectedActions: [