Redirect user to visited page after login

This commit is contained in:
Christian Cueni 2019-10-02 16:28:29 +02:00
parent 062269f030
commit 9783bd802a
2 changed files with 6 additions and 3 deletions

View File

@ -114,12 +114,13 @@ function getCookieValue(a) {
} }
function redirectIfLoginRequird(nameOfPage) { function redirectIfLoginRequird(nameOfPage) {
return publicPages.indexOf(nameOfPage) === -1 && getCookieValue('loginStatus') !== 'True'; return publicPages.indexOf(nameOfPage) === -1 && getCookieValue('loginStatus') !== 'true';
} }
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
if (redirectIfLoginRequird(to.name)) { if (redirectIfLoginRequird(to.name)) {
next('/login'); const redirectUrl = `/login?redirect=${to.path}`;
next(redirectUrl);
} else { } else {
next(); next();
} }

View File

@ -90,12 +90,14 @@ export default {
} }
) { ) {
try { try {
console.log('success', success)
if (success) { if (success) {
const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/'
that.$router.push(redirectUrl);
} else { } else {
that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.'; that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.';
} }
} catch (e) { } catch (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.';
} }
} }