|
1 | 1 | import { message } from 'ant-design-vue' |
2 | 2 | import i18n from '@/locales' |
| 3 | +import storage from '@/utils/storage' |
| 4 | +import { aesEncryptWithCustomKey } from '@/utils/crypto' |
3 | 5 | import { |
4 | 6 | getTokenFromCookie, |
5 | 7 | decodeToken, |
6 | 8 | getScopeFromCookie, |
7 | 9 | getTenantFromCookie, |
| 10 | + SESSION_LOGIN_USER_KEY, |
8 | 11 | } from '@/utils/auth' |
9 | 12 |
|
10 | 13 | export default { |
@@ -33,6 +36,14 @@ export default { |
33 | 36 | this._authTabHideLoading = null |
34 | 37 | } |
35 | 38 | }, |
| 39 | + // Cookie 用户与当前 Tab sessionStorage 对齐,避免 checkSessionUser 误判登出 |
| 40 | + syncSessionLoginUser (userId) { |
| 41 | + if (!userId) { |
| 42 | + storage.session.remove(SESSION_LOGIN_USER_KEY) |
| 43 | + return |
| 44 | + } |
| 45 | + storage.session.set(SESSION_LOGIN_USER_KEY, aesEncryptWithCustomKey(userId, 'cloudpods')) |
| 46 | + }, |
36 | 47 | async syncAuthFromCookie () { |
37 | 48 | if (document.visibilityState !== 'visible') return |
38 | 49 |
|
@@ -73,6 +84,7 @@ export default { |
73 | 84 | if (cookieLoggedIn && !storeLoggedIn) { |
74 | 85 | if (this.authTabSyncing) return |
75 | 86 | this.authTabSyncing = true |
| 87 | + this.syncSessionLoginUser(cookieUserId) |
76 | 88 | this.$store.commit('auth/SET_SCOPE', cookieScope) |
77 | 89 | if (cookieTenant) this.$store.commit('auth/SET_TENANT', cookieTenant) |
78 | 90 | this.$store.commit('auth/UPDATE_AUTH') |
@@ -101,6 +113,9 @@ export default { |
101 | 113 | const tenantChanged = cookieTenant !== storeTenant |
102 | 114 | const scopeChanged = cookieScope !== storeScope |
103 | 115 | if (userChanged || tenantChanged || scopeChanged) { |
| 116 | + if (userChanged) { |
| 117 | + this.syncSessionLoginUser(cookieUserId) |
| 118 | + } |
104 | 119 | this.$store.commit('auth/SET_SCOPE', cookieScope) |
105 | 120 | if (cookieTenant) this.$store.commit('auth/SET_TENANT', cookieTenant) |
106 | 121 | this.$store.commit('auth/UPDATE_AUTH') |
|
0 commit comments