Skip to content

Commit 19f4bd5

Browse files
authored
Merge pull request #9814 from GuoLiBin6/fix/glb-to-4.0/src
fix: user async
2 parents 9760d08 + ac6f1d0 commit 19f4bd5

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/mixins/authTabSync.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { message } from 'ant-design-vue'
22
import i18n from '@/locales'
3+
import storage from '@/utils/storage'
4+
import { aesEncryptWithCustomKey } from '@/utils/crypto'
35
import {
46
getTokenFromCookie,
57
decodeToken,
68
getScopeFromCookie,
79
getTenantFromCookie,
10+
SESSION_LOGIN_USER_KEY,
811
} from '@/utils/auth'
912

1013
export default {
@@ -33,6 +36,14 @@ export default {
3336
this._authTabHideLoading = null
3437
}
3538
},
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+
},
3647
async syncAuthFromCookie () {
3748
if (document.visibilityState !== 'visible') return
3849

@@ -73,6 +84,7 @@ export default {
7384
if (cookieLoggedIn && !storeLoggedIn) {
7485
if (this.authTabSyncing) return
7586
this.authTabSyncing = true
87+
this.syncSessionLoginUser(cookieUserId)
7688
this.$store.commit('auth/SET_SCOPE', cookieScope)
7789
if (cookieTenant) this.$store.commit('auth/SET_TENANT', cookieTenant)
7890
this.$store.commit('auth/UPDATE_AUTH')
@@ -101,6 +113,9 @@ export default {
101113
const tenantChanged = cookieTenant !== storeTenant
102114
const scopeChanged = cookieScope !== storeScope
103115
if (userChanged || tenantChanged || scopeChanged) {
116+
if (userChanged) {
117+
this.syncSessionLoginUser(cookieUserId)
118+
}
104119
this.$store.commit('auth/SET_SCOPE', cookieScope)
105120
if (cookieTenant) this.$store.commit('auth/SET_TENANT', cookieTenant)
106121
this.$store.commit('auth/UPDATE_AUTH')

0 commit comments

Comments
 (0)