From 9783bd802a872bb421931926984197478e275d87 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Wed, 2 Oct 2019 16:28:29 +0200 Subject: [PATCH] Redirect user to visited page after login --- client/src/main.js | 5 +++-- client/src/pages/login.vue | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/src/main.js b/client/src/main.js index 45559d88..cdb59a5d 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -114,12 +114,13 @@ function getCookieValue(a) { } function redirectIfLoginRequird(nameOfPage) { - return publicPages.indexOf(nameOfPage) === -1 && getCookieValue('loginStatus') !== 'True'; + return publicPages.indexOf(nameOfPage) === -1 && getCookieValue('loginStatus') !== 'true'; } router.beforeEach((to, from, next) => { if (redirectIfLoginRequird(to.name)) { - next('/login'); + const redirectUrl = `/login?redirect=${to.path}`; + next(redirectUrl); } else { next(); } diff --git a/client/src/pages/login.vue b/client/src/pages/login.vue index bc33bce7..ec35d3ac 100644 --- a/client/src/pages/login.vue +++ b/client/src/pages/login.vue @@ -90,12 +90,14 @@ export default { } ) { try { - console.log('success', success) if (success) { + const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/' + that.$router.push(redirectUrl); } else { that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.'; } } catch (e) { + console.warn(e); that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'; } }