From 8ac5ab67e9e352a97574ffe32cb7a1d35500af4f Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Wed, 12 May 2021 13:23:57 +0200 Subject: [PATCH] Handle redirect after successful login in frontend --- client/src/main.js | 10 ++++++++-- client/src/router/index.js | 11 ++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/client/src/main.js b/client/src/main.js index 5065a890..457e25dc 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -6,7 +6,7 @@ import VueVimeoPlayer from 'vue-vimeo-player'; import apolloClientFactory from './graphql/client'; import VueApollo from 'vue-apollo'; import App from './App'; -import router from './router'; +import {router, postLoginRederictUrlKey} from './router'; import store from '@/store/index'; import VueScrollTo from 'vue-scrollto'; import {Validator, install as VeeValidate} from 'vee-validate/dist/vee-validate.minimal.esm.js'; @@ -161,7 +161,13 @@ router.beforeEach(async (to, from, next) => { } if (unauthorizedAccess(to)) { - const redirectUrl = `/hello?redirect=${to.path}`; + const postLoginRedirectionUrl = to.path; + const redirectUrl = `/api/oauth/login/`; + + if (window.localStorage) { + localStorage.setItem(postLoginRederictUrlKey, postLoginRedirectionUrl); + } + next(redirectUrl); return; } diff --git a/client/src/router/index.js b/client/src/router/index.js index 962dd12a..c509035c 100644 --- a/client/src/router/index.js +++ b/client/src/router/index.js @@ -26,6 +26,8 @@ import roomRoutes from './room.routes'; import store from '@/store/index'; import {LAYOUT_SIMPLE} from '@/router/core.constants'; +const postLoginRederictUrlKey = 'postLoginRedirectionUrl'; + const routes = [ { path: '/', @@ -104,6 +106,12 @@ const routes = [ return '/verify-email'; case 'no_valid_license': return '/verify-email'; + case 'success': + if (window.localStorage && localStorage.getItem(postLoginRederictUrlKey)) { + const redirectUrl = localStorage.getItem(postLoginRederictUrlKey); + localStorage.removeItem(postLoginRederictUrlKey); + return redirectUrl; + } default: return '/unknown'; } @@ -137,4 +145,5 @@ router.afterEach((to, from) => { store.commit('setEditModule', false); store.dispatch('showMobileNavigation', false); }); -export default router; + +export {router, postLoginRederictUrlKey};