修复客服后台聊天无实时刷新
后台 token 仅存 httpOnly cookie,localStorage 无 access token, useChatSSE 在空 token 时提前 return,导致后台 SSE 从未建立连接, 只有手动刷新才出消息。 - 前端:后台 SSE 不再因空 token 返回,去掉 query token, 改用 withCredentials 依赖 cookie 鉴权 - 后端:新增 Hub.NotifyAllAdmins,新消息与新会话广播给所有在线客服, 使「未分配 / 全部」视图实时刷新(参与者客服重复收到由前端按 id 去重) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
9271f47553
commit
cc1c0d33de
@@ -40,10 +40,12 @@ export function useChatSSE(scope: AuthScope, endpoint: string) {
|
||||
function connect() {
|
||||
if (stopped || source) return
|
||||
const token = getAccessToken(scope)
|
||||
if (!token) return
|
||||
// 用户端通过 query token 鉴权;后台 token 存于 httpOnly cookie,
|
||||
// localStorage 无 token,连接时依赖浏览器自动携带的 cookie,不能因空 token 提前返回。
|
||||
if (scope !== 'admin' && !token) return
|
||||
|
||||
const url = `${endpoint}?token=${encodeURIComponent(token)}`
|
||||
source = new EventSource(url)
|
||||
const url = scope === 'admin' ? endpoint : `${endpoint}?token=${encodeURIComponent(token)}`
|
||||
source = new EventSource(url, { withCredentials: true })
|
||||
|
||||
source.addEventListener('connected', () => {
|
||||
connected.value = true
|
||||
|
||||
Reference in New Issue
Block a user