liuq 3 miesięcy temu
rodzic
commit
d914e48e84
2 zmienionych plików z 9 dodań i 2 usunięć
  1. 8 1
      frontend/src/router/index.ts
  2. 1 1
      frontend/src/views/Login.vue

+ 8 - 1
frontend/src/router/index.ts

@@ -127,6 +127,14 @@ const router = createRouter({
 })
 
 router.beforeEach((to, from, next) => {
+  const token = localStorage.getItem('token')
+
+  // If user is already logged in and tries to access login page, redirect to dashboard
+  if (token && to.path === '/login') {
+    next('/dashboard')
+    return
+  }
+
   // Public routes
   const publicRoutes = ['/login', '/register', '/consent', '/reset-password', '/setup']
   if (publicRoutes.includes(to.path)) {
@@ -134,7 +142,6 @@ router.beforeEach((to, from, next) => {
     return
   }
 
-  const token = localStorage.getItem('token')
   if (to.meta.requiresAuth && !token) {
     next('/login')
   } else {

+ 1 - 1
frontend/src/views/Login.vue

@@ -97,7 +97,7 @@ const handleLogin = async () => {
         remember_me: loginForm.remember_me
       })
       ElMessage.success('登录成功')
-      router.push('/dashboard')
+      router.push('/dashboard/launchpad')
     }
   } catch (error) {
     // Error handled in interceptor