Skip to content

Commit b3d72c0

Browse files
committed
feat(project): remove login redirect when user switching.
1 parent ad1d8c1 commit b3d72c0

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/store/modules/auth/index.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
6565
localStg.set('lastLoginUserId', userInfo.userId);
6666
}
6767

68-
/** Check if current login user is different from previous login user If different, clear all tabs */
69-
function checkTabClear() {
68+
/**
69+
* Check if current login user is different from previous login user If different, clear all tabs
70+
*
71+
* @returns {boolean} Whether to clear all tabs
72+
*/
73+
function checkTabClear(): boolean {
7074
if (!userInfo.userId) {
71-
return;
75+
return false;
7276
}
7377

7478
const lastLoginUserId = localStg.get('lastLoginUserId');
@@ -77,9 +81,12 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
7781
if (!lastLoginUserId || lastLoginUserId !== userInfo.userId) {
7882
localStg.remove('globalTabs');
7983
tabStore.clearTabs();
84+
localStg.remove('lastLoginUserId');
85+
return true;
8086
}
8187

8288
localStg.remove('lastLoginUserId');
89+
return false;
8390
}
8491

8592
/**
@@ -98,7 +105,15 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
98105
const pass = await loginByToken(loginToken);
99106

100107
if (pass) {
101-
await redirectFromLogin(redirect);
108+
// Check if the tab needs to be cleared
109+
const isClear = checkTabClear();
110+
let needRedirect = redirect;
111+
112+
if (isClear) {
113+
// If the tab needs to be cleared,it means we don't need to redirect.
114+
needRedirect = false;
115+
}
116+
await redirectFromLogin(needRedirect);
102117

103118
window.$notification?.success({
104119
title: $t('page.login.common.loginSuccess'),
@@ -124,9 +139,6 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
124139
if (pass) {
125140
token.value = loginToken.token;
126141

127-
// Check if the tab needs to be cleared
128-
checkTabClear();
129-
130142
return true;
131143
}
132144

0 commit comments

Comments
 (0)