fix(刷新请求头工具): 解决没有更新用户信息的bug,在获取到请求头后直接重新获取用户信息
This commit is contained in:
parent
fa91e7dba8
commit
8d7ac2245a
@ -11,6 +11,8 @@ import {
|
||||
isAppConnected,
|
||||
getAppHeaderInfo,
|
||||
} from '@/utils/appConnectionManager.js'
|
||||
import { getUserId, setUserInfo } from '@/utils/userStore.js'
|
||||
import { getUserIdentity, getMemberProfile } from '@/api/wallet.js'
|
||||
import { useRouter } from 'vue-router'
|
||||
const router = useRouter()
|
||||
|
||||
@ -24,6 +26,30 @@ const defaultOnFailed = (error) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* APP连接成功后获取用户信息
|
||||
* @private
|
||||
*/
|
||||
const fetchUserInfoAfterConnection = async () => {
|
||||
try {
|
||||
console.debug('👤 Fetching user info after connection...')
|
||||
|
||||
const response = await getMemberProfile()
|
||||
|
||||
if (response && response.status && response.body) {
|
||||
// 缓存用户信息
|
||||
console.debug('✅ User info cached successfully')
|
||||
setUserInfo(response.body, null)
|
||||
} else {
|
||||
console.warn('⚠️ Failed to get team entry or invalid response')
|
||||
}
|
||||
} catch (error) {
|
||||
// 这里不抛出错误,因为APP连接已经成功
|
||||
// 用户信息获取失败可以在后续的身份检查中处理
|
||||
console.warn('⚠️ Failed to fetch user info after connection:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一的APP连接工具函数
|
||||
* @param {Function} onConnected - 连接成功回调
|
||||
@ -40,8 +66,8 @@ export const connectToApp = async (onConnected, onFailed = defaultOnFailed) => {
|
||||
console.debug('🌐 Browser environment detected')
|
||||
console.groupEnd()
|
||||
|
||||
// 触发连接成功回调
|
||||
if (onConnected) onConnected()
|
||||
await fetchUserInfoAfterConnection() //获取用户信息
|
||||
if (onConnected) onConnected() // 触发连接成功回调
|
||||
|
||||
return { success: true, environment: 'browser' }
|
||||
}
|
||||
@ -58,8 +84,8 @@ export const connectToApp = async (onConnected, onFailed = defaultOnFailed) => {
|
||||
|
||||
console.groupEnd()
|
||||
|
||||
// 触发连接成功回调
|
||||
if (onConnected) onConnected()
|
||||
await fetchUserInfoAfterConnection() //获取用户信息
|
||||
if (onConnected) onConnected() // 触发连接成功回调
|
||||
|
||||
return { success: true, environment: 'app', fromCache: true }
|
||||
}
|
||||
@ -71,8 +97,8 @@ export const connectToApp = async (onConnected, onFailed = defaultOnFailed) => {
|
||||
console.debug('✅ Connected via existing process')
|
||||
console.groupEnd()
|
||||
|
||||
// 触发连接成功回调
|
||||
if (onConnected) onConnected()
|
||||
await fetchUserInfoAfterConnection() //获取用户信息
|
||||
if (onConnected) onConnected() // 触发连接成功回调
|
||||
|
||||
return { success: true, environment: 'app', fromCache: true }
|
||||
}
|
||||
@ -121,8 +147,8 @@ export const connectToApp = async (onConnected, onFailed = defaultOnFailed) => {
|
||||
console.debug('✅ Connection completed successfully')
|
||||
console.groupEnd()
|
||||
|
||||
// 触发连接成功回调
|
||||
if (onConnected) onConnected()
|
||||
await fetchUserInfoAfterConnection() //获取用户信息
|
||||
if (onConnected) onConnected() // 触发连接成功回调
|
||||
|
||||
return connectionResult
|
||||
} catch (error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user