fix: update token retrieval logic in handleRedirectCallback and remove unused parseSSE function
This commit is contained in:
+4
-18
@@ -165,29 +165,15 @@ async function handleRedirectCallback(): Promise<string | null> {
|
||||
})
|
||||
|
||||
const result = await response.json()
|
||||
if (response.ok && result.access_token) {
|
||||
setLocalToken(result.access_token)
|
||||
return result.access_token
|
||||
const token = result.id_token || result.access_token
|
||||
if (response.ok && token) {
|
||||
setLocalToken(token)
|
||||
return token
|
||||
}
|
||||
|
||||
throw new Error(result.error_description || 'OIDC callback failed')
|
||||
}
|
||||
|
||||
function parseSSE(text: string, onData: (chunk: string) => void) {
|
||||
const events = text.split('\n\n')
|
||||
for (const event of events) {
|
||||
const trimmed = event.trim()
|
||||
if (!trimmed) continue
|
||||
const lines = trimmed.split('\n')
|
||||
const dataLines = lines
|
||||
.filter((line) => line.startsWith('data:'))
|
||||
.map((line) => line.replace(/^data:\s?/, ''))
|
||||
if (dataLines.length) {
|
||||
onData(dataLines.join('\n'))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function App() {
|
||||
const [messages, setMessages] = useState<Message[]>([])
|
||||
const [input, setInput] = useState('')
|
||||
|
||||
Reference in New Issue
Block a user