mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-03 23:00:18 +01:00
🛣️ fix: Chat Stream Hangup (#4822)
Embedded sse.js code converted into an external dependency. Custom access token refresh logic moved to useSSE.ts hook. Closes #4820
This commit is contained in:
parent
ebae494337
commit
daa8e878d2
6 changed files with 64 additions and 275 deletions
|
|
@ -1,7 +1,7 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import axios, { AxiosRequestConfig, AxiosError } from 'axios';
|
||||
import { setTokenHeader } from './headers-helpers';
|
||||
import axios, { AxiosError, AxiosRequestConfig } from 'axios';
|
||||
import * as endpoints from './api-endpoints';
|
||||
import { setTokenHeader } from './headers-helpers';
|
||||
|
||||
async function _get<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
|
||||
const response = await axios.get(url, { ...options });
|
||||
|
|
@ -65,6 +65,11 @@ let failedQueue: { resolve: (value?: any) => void; reject: (reason?: any) => voi
|
|||
|
||||
const refreshToken = (retry?: boolean) => _post(endpoints.refreshToken(retry));
|
||||
|
||||
const dispatchTokenUpdatedEvent = (token: string) => {
|
||||
setTokenHeader(token);
|
||||
window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: token }));
|
||||
};
|
||||
|
||||
const processQueue = (error: AxiosError | null, token: string | null = null) => {
|
||||
failedQueue.forEach((prom) => {
|
||||
if (error) {
|
||||
|
|
@ -109,8 +114,7 @@ axios.interceptors.response.use(
|
|||
|
||||
if (token) {
|
||||
originalRequest.headers['Authorization'] = 'Bearer ' + token;
|
||||
setTokenHeader(token);
|
||||
window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: token }));
|
||||
dispatchTokenUpdatedEvent(token);
|
||||
processQueue(null, token);
|
||||
return await axios(originalRequest);
|
||||
} else {
|
||||
|
|
@ -139,4 +143,5 @@ export default {
|
|||
deleteWithOptions: _deleteWithOptions,
|
||||
patch: _patch,
|
||||
refreshToken,
|
||||
dispatchTokenUpdatedEvent,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue