From 113b1d8d9a172faa5c91db8278e0c6a074b0c759 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Wed, 22 Jan 2020 08:43:01 +0100 Subject: [PATCH] Reset cache on logout, refactor logout --- client/src/components/LogoutWidget.vue | 2 +- client/src/components/UserWidget.vue | 2 +- client/src/main.js | 11 ++++++- client/src/pages/login.vue | 13 ++------ client/src/pages/registration.vue | 44 +++++++++++--------------- 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/client/src/components/LogoutWidget.vue b/client/src/components/LogoutWidget.vue index 20fba9e5..7ffea46f 100644 --- a/client/src/components/LogoutWidget.vue +++ b/client/src/components/LogoutWidget.vue @@ -14,7 +14,7 @@ this.$apollo.mutate({ mutation: LOGOUT_MUTATION, }).then(({data}) => { - if (data.logout.success) { location.replace('/') } + if (data.logout.success) { location.replace('/logout') } }); } } diff --git a/client/src/components/UserWidget.vue b/client/src/components/UserWidget.vue index dfddf48e..7de9e75d 100644 --- a/client/src/components/UserWidget.vue +++ b/client/src/components/UserWidget.vue @@ -68,7 +68,7 @@ mutation: LOGOUT_MUTATION, }).then(({data}) => { if (data.logout.success) { - location.replace('/') + location.replace('/logout') } }); } diff --git a/client/src/main.js b/client/src/main.js index 341a5d02..63336b3e 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -138,13 +138,22 @@ function redirectStudentsWithoutClass() { } router.beforeEach(async (to, from, next) => { + // handle logout + if (to.path === '/logout') { + privateApolloClient.resetStore(); + next({name: 'login'}); + return + } + if (unauthorizedAccess(to)) { const redirectUrl = `/login?redirect=${to.path}`; next(redirectUrl); + return } if (to.name !== 'noClass' && loginRequired(to) && await redirectStudentsWithoutClass()) { - router.push({name: 'noClass'}) + next({name: 'noClass'}) + return } next(); diff --git a/client/src/pages/login.vue b/client/src/pages/login.vue index 94155c82..47860638 100644 --- a/client/src/pages/login.vue +++ b/client/src/pages/login.vue @@ -91,14 +91,8 @@ export default { passwordInput: this.password } }, - update( - store, - { - data: { - login - } - } - ) { + fetchPolicy: 'no-cache', + }).then(({data: {login}}) => { try { if (login.success) { const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/' @@ -118,7 +112,6 @@ export default { console.warn(e); that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'; } - } }); } }); @@ -128,7 +121,7 @@ export default { this.password = ''; this.submitted = false; this.$validator.reset(); - } + }, }, data() { diff --git a/client/src/pages/registration.vue b/client/src/pages/registration.vue index a58c4e12..7ff3d1b8 100644 --- a/client/src/pages/registration.vue +++ b/client/src/pages/registration.vue @@ -144,32 +144,26 @@ export default { licenseKeyInput: this.licenseKey, } }, - update( - store, - { - data: { - registration: { success, errors } - } - } - ) { - try { - if (success) { - window.location.href = '/registration/set-password/done/'; - } else { - errors.forEach(function(error) { - switch (error.field) { - case 'email': - that.emailErrors = ['Die angegebene E-Mail ist bereits registriert.']; - break; - case 'license_key': - that.licenseKeyErrors = ['Die angegebenen Lizenz ist unglültig']; - } - }) - } - } catch (e) { - console.warn(e); - that.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'; + fetchPolicy: 'no-cache' + }) + .then(({data: {registration: { success, errors }}}) => { + try { + if (success) { + window.location.href = '/registration/set-password/done/'; + } else { + errors.forEach(function(error) { + switch (error.field) { + case 'email': + that.emailErrors = ['Die angegebene E-Mail ist bereits registriert.']; + break; + case 'license_key': + that.licenseKeyErrors = ['Die angegebenen Lizenz ist unglültig']; + } + }) } + } catch (e) { + console.warn(e); + that.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'; } }); }