diff --git a/.env b/.env index 454649d89..b9c4ccffc 100644 --- a/.env +++ b/.env @@ -1,7 +1,7 @@ VITE_API_URL = '/api' VITE_CHAT_URL = '/chat' -VITE_AUTH_MODULE_URL = '/app/auth' +VITE_AUTH_URL = '/app/auth' VITE_ADMIN_URL = '/admin' VITE_AGENT_URL = '/workspace' diff --git a/.env.development b/.env.development index 75b2ee2e5..2b0b5cdc7 100644 --- a/.env.development +++ b/.env.development @@ -1,7 +1,7 @@ VITE_API_URL = 'https://dev.webitel.com/api' VITE_CHAT_URL = 'chat' -VITE_AUTH_MODULE_URL = 'http://dev.webitel.com/app/auth' +VITE_AUTH_URL = 'http://dev.webitel.com/app/auth' VITE_ADMIN_URL = 'https://dev.webitel.com/admin' VITE_AGENT_URL = 'https://dev.webitel.com/workspace' diff --git a/package-lock.json b/package-lock.json index 0e7f4a224..321dbbb61 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,19 @@ { "name": "web-client", - "version": "24.02.0", + "version": "24.02.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "web-client", - "version": "24.02.0", + "version": "24.02.1", "dependencies": { "@vue/compat": "^3.2.47", "@vuelidate/core": "^2.0.0", "@vuelidate/validators": "^2.0.0", "@vueuse/core": "^10.3.0", "@webitel/flow-ui-sdk": "^0.1.14", - "@webitel/ui-sdk": "^24.4.11", + "@webitel/ui-sdk": "^24.4.13", "axios": "^1.6.5", "clipboard-copy": "^4.0.1", "cron-validator": "^1.3.1", @@ -1501,9 +1501,9 @@ } }, "node_modules/@webitel/ui-sdk": { - "version": "24.4.11", - "resolved": "https://registry.npmjs.org/@webitel/ui-sdk/-/ui-sdk-24.4.11.tgz", - "integrity": "sha512-2bzJ380JSpWTwyElJY9VZc8xYeqISEiL7PJnS/vp90KTWgCMVd9oVOLWC22uV4Xp1Q16v9PPS3eB3vPK7G2lSQ==", + "version": "24.4.13", + "resolved": "https://registry.npmjs.org/@webitel/ui-sdk/-/ui-sdk-24.4.13.tgz", + "integrity": "sha512-LKB3UGRKgHKNJpAhyl8+IjPQBpC3tSm69ejTmzqEglUTWSIdhQAT2O6AjcvZ7P6+0RTfKgSwPHr29DQRR9ZQsA==", "dependencies": { "@floating-ui/vue": "^1.0.1", "@vuelidate/core": "^2.0.3", diff --git a/package.json b/package.json index 3b8c81148..6e4b5136b 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "@vuelidate/validators": "^2.0.0", "@vueuse/core": "^10.3.0", "@webitel/flow-ui-sdk": "^0.1.14", - "@webitel/ui-sdk": "^24.4.11", + "@webitel/ui-sdk": "^24.4.13", "axios": "^1.6.5", "clipboard-copy": "^4.0.1", "cron-validator": "^1.3.1", diff --git a/src/app/router/router.js b/src/app/router/router.js index 3bfcaafd2..6a293c5f7 100755 --- a/src/app/router/router.js +++ b/src/app/router/router.js @@ -1,4 +1,3 @@ -import Auth from '@webitel/ui-sdk/src/modules/Userinfo/components/the-auth.vue'; import { createRouter, createWebHistory } from 'vue-router'; import store from '../store/store'; import RouteNames from './_internals/RouteNames.enum'; @@ -80,7 +79,7 @@ const checkAppAccess = (to, from, next) => { if (hasReadAccess) { next(); } else { - // next('/access-denied'); + next('/access-denied'); } }; @@ -100,11 +99,6 @@ const router = createRouter({ return { left: 0, top: 0 }; }, routes: [ - { - path: '/auth', - name: RouteNames.AUTH, - component: Auth, - }, { path: '/', name: RouteNames.APPLICATION_HUB, @@ -741,12 +735,18 @@ const router = createRouter({ }); router.beforeEach((to, from, next) => { - if (!(to.path === '/auth')) { - if (!localStorage.getItem('access-token')) { - next('/auth'); - } + if (!localStorage.getItem('access-token') && !to.query.accessToken) { + const desiredUrl = `${window.location.origin}${encodeURIComponent(to.fullPath)}`; + const authUrl = import.meta.env.VITE_AUTH_URL; + window.location.href = `${authUrl}?redirectTo=${desiredUrl}`; + } else if (to.query.accessToken) { + // assume that access token was set from query before app initialization in main.js + const newQuery = { ...to.query }; + delete newQuery.accessToken; + next({ ...to, query: newQuery }); + } else { + next(); } - next(); }); export default router; diff --git a/src/main.js b/src/main.js index e7be70fcc..1caba7c7b 100755 --- a/src/main.js +++ b/src/main.js @@ -2,8 +2,7 @@ import { createApp } from 'vue'; // dont know why but when i import dropzone css is css files, it brakes build on firefox (only build!) import 'vue2-dropzone/dist/vue2Dropzone.min.css'; import './app/assets/icons/sprite'; -import ActionComponents from './app/components/actions'; -import App from './app/components/app.vue'; +import instance from './app/api/instance'; /* Don't know why, but without this empty file import styles just breaking :/ @@ -11,6 +10,8 @@ I suppose, it's a problem with webpack or sass/sass loader. I think, this issue should go on migration to Vue 3, so I left it "as is". */ import './app/css/do-not-delete-me.scss'; +import ActionComponents from './app/components/actions'; +import App from './app/components/app.vue'; import i18n from './app/locale/i18n'; import BreakpointPlugin from './app/plugins/breakpoint'; import './app/plugins/webitel-flow-ui'; @@ -23,7 +24,25 @@ const fetchConfig = async () => { return response.json(); }; -const initSession = async () => store.dispatch('userinfo/OPEN_SESSION'); +const setTokenFromUrl = () => { + try { + const queryMap = window.location.search.slice(1) + .split('&') + .reduce((obj, query) => { + const [key, value] = query.split('='); + obj[key] = value; + return obj; + }, {}); + + if (queryMap.accessToken) { + localStorage.setItem('access-token', queryMap.accessToken); + } + } catch (err) { + console.error('Error restoring token from url', err); + } +}; + +const initSession = async () => store.dispatch('userinfo/OPEN_SESSION', { instance }); const createVueInstance = () => { const app = createApp(App) @@ -44,6 +63,8 @@ const createVueInstance = () => { (async () => { let config = {}; try { + setTokenFromUrl(); + config = await fetchConfig(); await initSession(); } catch (err) { diff --git a/src/modules/_reusable/app-header/components/app-header.vue b/src/modules/_reusable/app-header/components/app-header.vue index 0ece5cf63..25fa6fcb6 100644 --- a/src/modules/_reusable/app-header/components/app-header.vue +++ b/src/modules/_reusable/app-header/components/app-header.vue @@ -28,10 +28,8 @@