Commit 63732688 by Liu

fix:运行报错

parent 396bb0c0
This source diff could not be displayed because it is too large. You can view the blob instead.
packages:
- 'fixtures/*'
- fixtures/*
ignoredBuiltDependencies:
- core-js
- simple-git-hooks
- unrs-resolver
......@@ -68,11 +68,20 @@ export function fetchStreamResponse(url: string, body: Record<string, any>, onMe
})
})
}
const tokenStr = window.localStorage.getItem('__TOKEN__') || '""'
let token = ''
try {
token = JSON.parse(tokenStr)
}
catch {
token = ''
}
fetch(url, {
headers: {
'accept': 'text/event-stream',
'Content-Type': 'application/json',
'X-Token': JSON.parse(window.localStorage.getItem('__TOKEN__') || ''),
'X-Token': token,
},
method: 'POST',
body: JSON.stringify(body),
......
......@@ -27,7 +27,18 @@ export function withRouteChangeHandler(WrappedComponent: React.ComponentType) {
else if (location.pathname.startsWith('/chat/')) {
const conversationId = location.pathname.split('/')[2]
if (!JSON.parse(window.localStorage.getItem('__TOKEN__') || '')) {
const tokenStr = window.localStorage.getItem('__TOKEN__') || '""'
let token = ''
try {
token = JSON.parse(tokenStr)
}
catch {
// 如果解析失败,说明没有有效的 token
navigate('/')
return // 提前返回,不执行后续的 dispatch
}
if (!token) {
// 如果没有有效的 token,重定向到首页
navigate('/')
return // 提前返回,不执行后续的 dispatch
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment