fix(auth): 解决认证错误处理和会话管理问题

- 替换 AUTH_INVALID_TOKEN_CODE 为 AUTH_RELOGIN_REQUIRED_CODES 数组支持多种错误码
- 实现 hasClearableSessionState 和 hasRecordedUnauthorizedSession 函数优化会话清理逻辑
- 添加 clearQueryCache 选项控制查询缓存清理行为
- 修复马来西亚手机号正则验证模式导致的用户名验证问题
- 更新 API 错误消息处理优先级,优先使用服务端返回的消息
- 添加服务器消息检查函数 hasServerMessage 避免重复错误提示
- 在登录表单中实现密码可见性切换功能
- 添加密码可见性国际化文案支持
- 实现页面历史记录抽屉组件和相关动效
- 优化模态框背景遮罩样式和键盘事件处理
- 调整多个组件的 z-index 层级避免显示冲突
This commit is contained in:
JiaJun
2026-06-01 17:46:01 +08:00
parent 87e8aca97d
commit 72b6de499e
51 changed files with 3812 additions and 149 deletions

View File

@@ -678,10 +678,13 @@ function applyRealtimeMessage(message: GameSocketMessage) {
export function useGameRealtimeSync() {
const accessToken = useAuthStore((state) => state.accessToken)
const authStatus = useAuthStore((state) => state.status)
const lastUnauthorizedAt = useAuthStore((state) => state.lastUnauthorizedAt)
const shouldConnectRealtime = useGameSessionStore(
(state) => state.shouldConnectRealtime,
)
const socketClientRef = useRef<GameSocketClient | null>(null)
const isReloginRequired =
authStatus === 'anonymous' && Boolean(lastUnauthorizedAt)
useEffect(() => {
if (sharedSocketDisconnectTimerId !== null) {
@@ -689,6 +692,26 @@ export function useGameRealtimeSync() {
sharedSocketDisconnectTimerId = null
}
if (isReloginRequired) {
sharedSocketClient?.disconnect()
sharedSocketClient = null
sharedSocketKey = null
socketClientRef.current = null
const gameSession = useGameSessionStore.getState()
gameSession.resetRealtimeConnectionRequest()
gameSession.syncConnection({
lastError: null,
latencyMs: null,
reconnectAttempt: 0,
status: 'disconnected',
transport: 'offline',
})
return
}
if (
!shouldConnectRealtime ||
authStatus !== 'authenticated' ||
@@ -810,10 +833,14 @@ export function useGameRealtimeSync() {
}, SOCKET_DISCONNECT_DELAY_MS)
socketClientRef.current = sharedSocketClient
}
}, [accessToken, authStatus, shouldConnectRealtime])
}, [accessToken, authStatus, isReloginRequired, shouldConnectRealtime])
useEffect(() => {
if (!shouldConnectRealtime || authStatus !== 'authenticated') {
if (
isReloginRequired ||
!shouldConnectRealtime ||
authStatus !== 'authenticated'
) {
return
}
@@ -869,5 +896,5 @@ export function useGameRealtimeSync() {
cancelled = true
window.clearInterval(intervalId)
}
}, [authStatus, shouldConnectRealtime])
}, [authStatus, isReloginRequired, shouldConnectRealtime])
}