From b6b1e0f2e0e045c1679e38f9a2c7ade3349be637 Mon Sep 17 00:00:00 2001 From: chouchouji <70570907+chouchouji@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:24:39 +0800 Subject: [PATCH] [Improvement] Redirect to login page if user doesn't login (#3274) Co-authored-by: ZhouJinsong Co-authored-by: baiyangtx Co-authored-by: ConradJam --- amoro-web/src/main.ts | 13 +++++++------ amoro-web/src/views/login/index.vue | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/amoro-web/src/main.ts b/amoro-web/src/main.ts index cc9d2047da..dd257eb2dc 100644 --- a/amoro-web/src/main.ts +++ b/amoro-web/src/main.ts @@ -71,16 +71,17 @@ RegisterComponents(app); finally { const store = useStore() router.beforeEach((to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => { - if (to.fullPath === '/login') { - if (store.userInfo.userName) { - return next('/') - } + // if no username in store and not go to login page, should redirect to login page + if (!store.userInfo.userName && to.path !== '/login') { store.setHistoryPath({ path: from.path, - query: { ...from.query }, + query: from.query, }) + next('/login') + } + else { + next() } - next() }) app.use(router) diff --git a/amoro-web/src/views/login/index.vue b/amoro-web/src/views/login/index.vue index 4818d09d9f..8092322d8f 100644 --- a/amoro-web/src/views/login/index.vue +++ b/amoro-web/src/views/login/index.vue @@ -18,7 +18,7 @@ limitations under the License.