Skip to content

Commit e27be2d

Browse files
authored
fix: successful login should not take you to the login page (#4056)
* fix: successful login should not take you to the login page * chore: use DEFAULT_HOME_PATH constants * chore: remove invalid spaces in script * fix: lint error
1 parent 9dce5b4 commit e27be2d

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

apps/web-antd/src/router/guard.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Router } from 'vue-router';
22

3-
import { LOGIN_PATH } from '@vben/constants';
3+
import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants';
44
import { preferences } from '@vben/preferences';
55
import { useAccessStore, useUserStore } from '@vben/stores';
66
import { startProgress, stopProgress } from '@vben/utils';
@@ -62,14 +62,20 @@ function setupAccessGuard(router: Router) {
6262
const userStore = useUserStore();
6363
const authStore = useAuthStore();
6464

65+
// 基本路由,这些路由不需要进入权限拦截
66+
if (coreRouteNames.includes(to.name as string)) {
67+
if (to.path === LOGIN_PATH && accessStore.accessToken) {
68+
return decodeURIComponent(
69+
(to.query?.redirect as string) || DEFAULT_HOME_PATH,
70+
);
71+
}
72+
return true;
73+
}
74+
6575
// accessToken 检查
6676
if (!accessStore.accessToken) {
67-
if (
68-
// 基本路由,这些路由不需要进入权限拦截
69-
coreRouteNames.includes(to.name as string) ||
70-
// 明确声明忽略权限访问权限,则可以访问
71-
to.meta.ignoreAccess
72-
) {
77+
// 明确声明忽略权限访问权限,则可以访问
78+
if (to.meta.ignoreAccess) {
7379
return true;
7480
}
7581

apps/web-ele/src/router/guard.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Router } from 'vue-router';
22

3-
import { LOGIN_PATH } from '@vben/constants';
3+
import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants';
44
import { preferences } from '@vben/preferences';
55
import { useAccessStore, useUserStore } from '@vben/stores';
66
import { startProgress, stopProgress } from '@vben/utils';
@@ -62,14 +62,20 @@ function setupAccessGuard(router: Router) {
6262
const userStore = useUserStore();
6363
const authStore = useAuthStore();
6464

65+
// 基本路由,这些路由不需要进入权限拦截
66+
if (coreRouteNames.includes(to.name as string)) {
67+
if (to.path === LOGIN_PATH && accessStore.accessToken) {
68+
return decodeURIComponent(
69+
(to.query?.redirect as string) || DEFAULT_HOME_PATH,
70+
);
71+
}
72+
return true;
73+
}
74+
6575
// accessToken 检查
6676
if (!accessStore.accessToken) {
67-
if (
68-
// 基本路由,这些路由不需要进入权限拦截
69-
coreRouteNames.includes(to.name as string) ||
70-
// 明确声明忽略权限访问权限,则可以访问
71-
to.meta.ignoreAccess
72-
) {
77+
// 明确声明忽略权限访问权限,则可以访问
78+
if (to.meta.ignoreAccess) {
7379
return true;
7480
}
7581

apps/web-naive/src/router/guard.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Router } from 'vue-router';
22

3-
import { LOGIN_PATH } from '@vben/constants';
3+
import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants';
44
import { preferences } from '@vben/preferences';
55
import { useAccessStore, useUserStore } from '@vben/stores';
66
import { startProgress, stopProgress } from '@vben/utils';
@@ -62,14 +62,20 @@ function setupAccessGuard(router: Router) {
6262
const userStore = useUserStore();
6363
const authStore = useAuthStore();
6464

65+
// 基本路由,这些路由不需要进入权限拦截
66+
if (coreRouteNames.includes(to.name as string)) {
67+
if (to.path === LOGIN_PATH && accessStore.accessToken) {
68+
return decodeURIComponent(
69+
(to.query?.redirect as string) || DEFAULT_HOME_PATH,
70+
);
71+
}
72+
return true;
73+
}
74+
6575
// accessToken 检查
6676
if (!accessStore.accessToken) {
67-
if (
68-
// 基本路由,这些路由不需要进入权限拦截
69-
coreRouteNames.includes(to.name as string) ||
70-
// 明确声明忽略权限访问权限,则可以访问
71-
to.meta.ignoreAccess
72-
) {
77+
// 明确声明忽略权限访问权限,则可以访问
78+
if (to.meta.ignoreAccess) {
7379
return true;
7480
}
7581

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"publint": "vsh publint",
5252
"reinstall": "pnpm clean --del-lock && pnpm bootstrap",
5353
"test:unit": "vitest",
54-
"update:deps": " pnpm update --latest --recursive",
54+
"update:deps": "pnpm update --latest --recursive",
5555
"version": "pnpm exec changeset version && pnpm install --no-frozen-lockfile"
5656
},
5757
"devDependencies": {

0 commit comments

Comments
 (0)