From 0022b99a16016091ad4d53e94d6f1e6ff0650ff8 Mon Sep 17 00:00:00 2001 From: dlohvinov Date: Thu, 21 Mar 2024 22:50:48 +0200 Subject: [PATCH 1/2] refactor: new auth refactor [WTEL-4374] --- .env | 2 +- .env.development | 2 +- package-lock.json | 12 +++++----- package.json | 2 +- src/app/router/router.js | 24 ++++++++++--------- src/main.js | 7 +++--- .../app-header/components/app-header.vue | 13 +++++----- src/modules/userinfo/store/userinfo.js | 9 ------- 8 files changed, 32 insertions(+), 39 deletions(-) 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..a874e313f 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,20 @@ const router = createRouter({ }); router.beforeEach((to, from, next) => { - if (!(to.path === '/auth')) { - if (!localStorage.getItem('access-token')) { - next('/auth'); + debugger; + if (!localStorage.getItem('access-token')) { + if (to.query.accessToken) { + localStorage.setItem('access-token', to.query.accessToken); + const newQuery = { ...to.query }; + delete newQuery.accessToken; + return next({ query: newQuery }); } + const desiredUrl = `${window.location.origin}${encodeURIComponent(to.fullPath)}`; + const authUrl = import.meta.env.VITE_AUTH_URL; + // console.info(`${authUrl}?redirectTo=${desiredUrl}`); + window.location.href = `${authUrl}?redirectTo=${desiredUrl}`; } - next(); + return next(); }); export default router; diff --git a/src/main.js b/src/main.js index e7be70fcc..ce41da575 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,7 @@ const fetchConfig = async () => { return response.json(); }; -const initSession = async () => store.dispatch('userinfo/OPEN_SESSION'); +const initSession = async () => store.dispatch('userinfo/OPEN_SESSION', { instance }); const createVueInstance = () => { const app = createApp(App) 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 @@