Merged in feature/clear-cache (pull request #44)

Reset cache on logout, refactor logout
This commit is contained in:
Christian Cueni 2020-02-04 20:30:10 +00:00 committed by Ramon Wenger
commit d829d898b8
5 changed files with 34 additions and 38 deletions

View File

@ -14,7 +14,7 @@
this.$apollo.mutate({ this.$apollo.mutate({
mutation: LOGOUT_MUTATION, mutation: LOGOUT_MUTATION,
}).then(({data}) => { }).then(({data}) => {
if (data.logout.success) { location.replace('/') } if (data.logout.success) { location.replace('/logout') }
}); });
} }
} }

View File

@ -68,7 +68,7 @@
mutation: LOGOUT_MUTATION, mutation: LOGOUT_MUTATION,
}).then(({data}) => { }).then(({data}) => {
if (data.logout.success) { if (data.logout.success) {
location.replace('/') location.replace('/logout')
} }
}); });
} }

View File

@ -138,13 +138,22 @@ function redirectStudentsWithoutClass() {
} }
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
// handle logout
if (to.path === '/logout') {
privateApolloClient.resetStore();
next({name: 'login'});
return
}
if (unauthorizedAccess(to)) { if (unauthorizedAccess(to)) {
const redirectUrl = `/login?redirect=${to.path}`; const redirectUrl = `/login?redirect=${to.path}`;
next(redirectUrl); next(redirectUrl);
return
} }
if (to.name !== 'noClass' && loginRequired(to) && await redirectStudentsWithoutClass()) { if (to.name !== 'noClass' && loginRequired(to) && await redirectStudentsWithoutClass()) {
router.push({name: 'noClass'}) next({name: 'noClass'})
return
} }
next(); next();

View File

@ -91,14 +91,8 @@ export default {
passwordInput: this.password passwordInput: this.password
} }
}, },
update( fetchPolicy: 'no-cache',
store, }).then(({data: {login}}) => {
{
data: {
login
}
}
) {
try { try {
if (login.success) { if (login.success) {
const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/' const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/'
@ -118,7 +112,6 @@ export default {
console.warn(e); console.warn(e);
that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'; that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
} }
}
}); });
} }
}); });
@ -128,7 +121,7 @@ export default {
this.password = ''; this.password = '';
this.submitted = false; this.submitted = false;
this.$validator.reset(); this.$validator.reset();
} },
}, },
data() { data() {

View File

@ -144,32 +144,26 @@ export default {
licenseKeyInput: this.licenseKey, licenseKeyInput: this.licenseKey,
} }
}, },
update( fetchPolicy: 'no-cache'
store, })
{ .then(({data: {registration: { success, errors }}}) => {
data: { try {
registration: { success, errors } if (success) {
} window.location.href = '/registration/set-password/done/';
} } else {
) { errors.forEach(function(error) {
try { switch (error.field) {
if (success) { case 'email':
window.location.href = '/registration/set-password/done/'; that.emailErrors = ['Die angegebene E-Mail ist bereits registriert.'];
} else { break;
errors.forEach(function(error) { case 'license_key':
switch (error.field) { that.licenseKeyErrors = ['Die angegebenen Lizenz ist unglültig'];
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.';
} }
} catch (e) {
console.warn(e);
that.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
} }
}); });
} }