Handle redirect after successful login in frontend

This commit is contained in:
Christian Cueni 2021-05-12 13:23:57 +02:00
parent 47a5266752
commit 8ac5ab67e9
2 changed files with 18 additions and 3 deletions

View File

@ -6,7 +6,7 @@ import VueVimeoPlayer from 'vue-vimeo-player';
import apolloClientFactory from './graphql/client'; import apolloClientFactory from './graphql/client';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import App from './App'; import App from './App';
import router from './router'; import {router, postLoginRederictUrlKey} from './router';
import store from '@/store/index'; import store from '@/store/index';
import VueScrollTo from 'vue-scrollto'; import VueScrollTo from 'vue-scrollto';
import {Validator, install as VeeValidate} from 'vee-validate/dist/vee-validate.minimal.esm.js'; 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)) { 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); next(redirectUrl);
return; return;
} }

View File

@ -26,6 +26,8 @@ import roomRoutes from './room.routes';
import store from '@/store/index'; import store from '@/store/index';
import {LAYOUT_SIMPLE} from '@/router/core.constants'; import {LAYOUT_SIMPLE} from '@/router/core.constants';
const postLoginRederictUrlKey = 'postLoginRedirectionUrl';
const routes = [ const routes = [
{ {
path: '/', path: '/',
@ -104,6 +106,12 @@ const routes = [
return '/verify-email'; return '/verify-email';
case 'no_valid_license': case 'no_valid_license':
return '/verify-email'; return '/verify-email';
case 'success':
if (window.localStorage && localStorage.getItem(postLoginRederictUrlKey)) {
const redirectUrl = localStorage.getItem(postLoginRederictUrlKey);
localStorage.removeItem(postLoginRederictUrlKey);
return redirectUrl;
}
default: default:
return '/unknown'; return '/unknown';
} }
@ -137,4 +145,5 @@ router.afterEach((to, from) => {
store.commit('setEditModule', false); store.commit('setEditModule', false);
store.dispatch('showMobileNavigation', false); store.dispatch('showMobileNavigation', false);
}); });
export default router;
export {router, postLoginRederictUrlKey};