mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
🔧 fix: URL params, package mismatch, typing, shared link redirect, and o1 (azure) (#4899)
* fix: double decoding of URL params * fix: prevent streaming options for O1 model (azure) * fix: update @langchain/openai to version 0.3.14 in package-lock.json * chore(AuthContext): typing * chore(useTimeout): typing * fix: shared link redirecting to login when code block includes "Run Code" button * fix: typing
This commit is contained in:
parent
85d92c2353
commit
2875380bf1
8 changed files with 41 additions and 22 deletions
|
|
@ -338,7 +338,7 @@ export const useRegisterUserMutation = (
|
|||
};
|
||||
|
||||
export const useRefreshTokenMutation = (): UseMutationResult<
|
||||
t.TRefreshTokenResponse,
|
||||
t.TRefreshTokenResponse | undefined,
|
||||
unknown,
|
||||
unknown,
|
||||
unknown
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import axios, { AxiosError, AxiosRequestConfig } from 'axios';
|
||||
import * as endpoints from './api-endpoints';
|
||||
import { setTokenHeader } from './headers-helpers';
|
||||
import type * as t from './types';
|
||||
|
||||
async function _get<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
|
||||
const response = await axios.get(url, { ...options });
|
||||
|
|
@ -63,7 +64,8 @@ async function _patch(url: string, data?: any) {
|
|||
let isRefreshing = false;
|
||||
let failedQueue: { resolve: (value?: any) => void; reject: (reason?: any) => void }[] = [];
|
||||
|
||||
const refreshToken = (retry?: boolean) => _post(endpoints.refreshToken(retry));
|
||||
const refreshToken = (retry?: boolean): Promise<t.TRefreshTokenResponse | undefined> =>
|
||||
_post(endpoints.refreshToken(retry));
|
||||
|
||||
const dispatchTokenUpdatedEvent = (token: string) => {
|
||||
setTokenHeader(token);
|
||||
|
|
@ -90,6 +92,7 @@ axios.interceptors.response.use(
|
|||
}
|
||||
|
||||
if (error.response.status === 401 && !originalRequest._retry) {
|
||||
console.warn('401 error, refreshing token');
|
||||
originalRequest._retry = true;
|
||||
|
||||
if (isRefreshing) {
|
||||
|
|
@ -107,16 +110,22 @@ axios.interceptors.response.use(
|
|||
isRefreshing = true;
|
||||
|
||||
try {
|
||||
const { token } = await refreshToken(
|
||||
const response = await refreshToken(
|
||||
// Handle edge case where we get a blank screen if the initial 401 error is from a refresh token request
|
||||
originalRequest.url?.includes('api/auth/refresh') ? true : false,
|
||||
originalRequest.url?.includes('api/auth/refresh') === true ? true : false,
|
||||
);
|
||||
|
||||
const token = response?.token ?? '';
|
||||
|
||||
if (token) {
|
||||
originalRequest.headers['Authorization'] = 'Bearer ' + token;
|
||||
dispatchTokenUpdatedEvent(token);
|
||||
processQueue(null, token);
|
||||
return await axios(originalRequest);
|
||||
} else if (window.location.href.includes('share/')) {
|
||||
console.log(
|
||||
`Refresh token failed from shared link, attempting request to ${originalRequest.url}`,
|
||||
);
|
||||
} else {
|
||||
window.location.href = '/login';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue