File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
4141 async function resetStore ( ) {
4242 const authStore = useAuthStore ( ) ;
4343
44+ recordUserId ( ) ;
45+
4446 clearAuthStorage ( ) ;
4547
4648 authStore . $reset ( ) ;
@@ -53,6 +55,33 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
5355 routeStore . resetStore ( ) ;
5456 }
5557
58+ /** Record the user ID of the previous login session Used to compare with the current user ID on next login */
59+ function recordUserId ( ) {
60+ if ( ! userInfo . userId ) {
61+ return ;
62+ }
63+
64+ // Store current user ID locally for next login comparison
65+ localStg . set ( 'lastLoginUserId' , userInfo . userId ) ;
66+ }
67+
68+ /** Check if current login user is different from previous login user If different, clear all tabs */
69+ function checkTabClear ( ) {
70+ if ( ! userInfo . userId ) {
71+ return ;
72+ }
73+
74+ const lastLoginUserId = localStg . get ( 'lastLoginUserId' ) ;
75+
76+ // Clear all tabs if current user is different from previous user
77+ if ( ! lastLoginUserId || lastLoginUserId !== userInfo . userId ) {
78+ localStg . remove ( 'globalTabs' ) ;
79+ tabStore . clearTabs ( ) ;
80+ }
81+
82+ localStg . remove ( 'lastLoginUserId' ) ;
83+ }
84+
5685 /**
5786 * Login
5887 *
@@ -95,6 +124,9 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
95124 if ( pass ) {
96125 token . value = loginToken . token ;
97126
127+ // Check if the tab needs to be cleared
128+ checkTabClear ( ) ;
129+
98130 return true ;
99131 }
100132
Original file line number Diff line number Diff line change @@ -37,5 +37,7 @@ declare namespace StorageType {
3737 layout : UnionKey . ThemeLayoutMode ;
3838 siderCollapse : boolean ;
3939 } ;
40+ /** The last login user id */
41+ lastLoginUserId : string ;
4042 }
4143}
You can’t perform that action at this time.
0 commit comments