mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
🛂 feat: OpenID Logout Redirect to end_session_endpoint (#5626)
* WIP: end session endpoint * refactor: move useGetBannerQuery outside of package * refactor: add queriesEnabled and move useGetEndpointsConfigQuery to data-provider (local) * refactor: move useGetEndpointsQuery import to data-provider * refactor: relocate useGetEndpointsQuery import to improve module organization * refactor: move `useGetStartupConfig` from package to `~/data-provider` * refactor: move useGetUserBalance to data-provider and update imports * refactor: update query enabled conditions to include config check * refactor: remove unused useConfigOverride import from useAppStartup * refactor: integrate queriesEnabled state into file and search queries and move useGetSearchEnabledQuery to data-provider (local) * refactor: move useGetUserQuery to data-provider and update imports * refactor: enhance loginUser mutation with success and error handling as pass in options to hook * refactor: update enabled condition in queries to handle undefined config * refactor: enhance authentication mutations with queriesEnabled state management * refactor: improve conditional rendering for error messages and feature flags in Login component * refactor: remove unused queriesEnabled state from AuthContextProvider * refactor: implement queriesEnabled state management in LoginLayout with timeout handling * refactor: add conditional check for end session endpoint in OpenID strategy * ci: fix tests after changes * refactor: remove endSessionEndpoint from user schema and update logoutController to use OpenID issuer's end_session_endpoint * refactor: update logoutController to use end_session_endpoint from issuer metadata
This commit is contained in:
parent
d93f5c9061
commit
45dd2b262f
73 changed files with 385 additions and 270 deletions
|
|
@ -133,11 +133,11 @@ export const updateTokenCount = (text: string) => {
|
|||
return request.post(endpoints.tokenizer(), { arg: text });
|
||||
};
|
||||
|
||||
export const login = (payload: t.TLoginUser) => {
|
||||
export const login = (payload: t.TLoginUser): Promise<t.TLoginResponse> => {
|
||||
return request.post(endpoints.login(), payload);
|
||||
};
|
||||
|
||||
export const logout = () => {
|
||||
export const logout = (): Promise<m.TLogoutResponse> => {
|
||||
return request.post(endpoints.logout());
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ export enum MutationKeys {
|
|||
fileDelete = 'fileDelete',
|
||||
updatePreset = 'updatePreset',
|
||||
deletePreset = 'deletePreset',
|
||||
loginUser = 'loginUser',
|
||||
logoutUser = 'logoutUser',
|
||||
refreshToken = 'refreshToken',
|
||||
avatarUpload = 'avatarUpload',
|
||||
speechToText = 'speechToText',
|
||||
textToSpeech = 'textToSpeech',
|
||||
|
|
|
|||
|
|
@ -5,12 +5,10 @@ import type {
|
|||
QueryObserverResult,
|
||||
} from '@tanstack/react-query';
|
||||
import { initialModelsConfig } from '../config';
|
||||
import type { TStartupConfig } from '../config';
|
||||
import { defaultOrderQuery } from '../types/assistants';
|
||||
import * as dataService from '../data-service';
|
||||
import * as m from '../types/mutations';
|
||||
import { QueryKeys } from '../keys';
|
||||
import request from '../request';
|
||||
import * as s from '../schemas';
|
||||
import * as t from '../types';
|
||||
|
||||
|
|
@ -31,18 +29,6 @@ export const useAbortRequestWithMessage = (): UseMutationResult<
|
|||
);
|
||||
};
|
||||
|
||||
export const useGetUserQuery = (
|
||||
config?: UseQueryOptions<t.TUser>,
|
||||
): QueryObserverResult<t.TUser> => {
|
||||
return useQuery<t.TUser>([QueryKeys.user], () => dataService.getUser(), {
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnMount: false,
|
||||
retry: false,
|
||||
...config,
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetMessagesByConvoId = <TData = s.TMessage[]>(
|
||||
id: string,
|
||||
config?: UseQueryOptions<s.TMessage[], unknown, TData>,
|
||||
|
|
@ -98,17 +84,6 @@ export const useGetSharedLinkQuery = (
|
|||
);
|
||||
};
|
||||
|
||||
export const useGetUserBalance = (
|
||||
config?: UseQueryOptions<string>,
|
||||
): QueryObserverResult<string> => {
|
||||
return useQuery<string>([QueryKeys.balance], () => dataService.getUserBalance(), {
|
||||
refetchOnWindowFocus: true,
|
||||
refetchOnReconnect: true,
|
||||
refetchOnMount: true,
|
||||
...config,
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetConversationByIdQuery = (
|
||||
id: string,
|
||||
config?: UseQueryOptions<s.TConversation>,
|
||||
|
|
@ -226,33 +201,6 @@ export const useRevokeAllUserKeysMutation = (): UseMutationResult<unknown> => {
|
|||
});
|
||||
};
|
||||
|
||||
export const useGetSearchEnabledQuery = (
|
||||
config?: UseQueryOptions<boolean>,
|
||||
): QueryObserverResult<boolean> => {
|
||||
return useQuery<boolean>([QueryKeys.searchEnabled], () => dataService.getSearchEnabled(), {
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnMount: false,
|
||||
...config,
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetEndpointsQuery = <TData = t.TEndpointsConfig>(
|
||||
config?: UseQueryOptions<t.TEndpointsConfig, unknown, TData>,
|
||||
): QueryObserverResult<TData> => {
|
||||
return useQuery<t.TEndpointsConfig, unknown, TData>(
|
||||
[QueryKeys.endpoints],
|
||||
() => dataService.getAIEndpoints(),
|
||||
{
|
||||
staleTime: Infinity,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnMount: false,
|
||||
...config,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const useGetModelsQuery = (
|
||||
config?: UseQueryOptions<t.TModelsConfig>,
|
||||
): QueryObserverResult<t.TModelsConfig> => {
|
||||
|
|
@ -343,20 +291,6 @@ export const useRegisterUserMutation = (
|
|||
);
|
||||
};
|
||||
|
||||
export const useRefreshTokenMutation = (): UseMutationResult<
|
||||
t.TRefreshTokenResponse | undefined,
|
||||
unknown,
|
||||
unknown,
|
||||
unknown
|
||||
> => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(() => request.refreshToken(), {
|
||||
onMutate: () => {
|
||||
queryClient.removeQueries();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useUserKeyQuery = (
|
||||
name: string,
|
||||
config?: UseQueryOptions<t.TCheckUserKeyResponse>,
|
||||
|
|
@ -428,17 +362,6 @@ export const useUpdateUserPluginsMutation = (
|
|||
});
|
||||
};
|
||||
|
||||
export const useGetStartupConfig = (
|
||||
config?: UseQueryOptions<TStartupConfig>,
|
||||
): QueryObserverResult<TStartupConfig> => {
|
||||
return useQuery<TStartupConfig>([QueryKeys.startupConfig], () => dataService.getStartupConfig(), {
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnMount: false,
|
||||
...config,
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetCustomConfigSpeechQuery = (
|
||||
config?: UseQueryOptions<t.TCustomConfigSpeechResponse>,
|
||||
): QueryObserverResult<t.TCustomConfigSpeechResponse> => {
|
||||
|
|
@ -453,14 +376,3 @@ export const useGetCustomConfigSpeechQuery = (
|
|||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const useGetBannerQuery = (
|
||||
config?: UseQueryOptions<t.TBannerResponse>,
|
||||
): QueryObserverResult<t.TBannerResponse> => {
|
||||
return useQuery<t.TBannerResponse>([QueryKeys.banner], () => dataService.getBanner(), {
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnMount: false,
|
||||
...config,
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -91,6 +91,10 @@ axios.interceptors.response.use(
|
|||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
if (originalRequest.url?.includes('/api/auth/logout') === true) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
if (error.response.status === 401 && !originalRequest._retry) {
|
||||
console.warn('401 error, refreshing token');
|
||||
originalRequest._retry = true;
|
||||
|
|
|
|||
|
|
@ -49,8 +49,6 @@ export type UpdatePresetOptions = MutationOptions<types.TPreset, types.TPreset>;
|
|||
|
||||
export type DeletePresetOptions = MutationOptions<PresetDeleteResponse, types.TPreset | undefined>;
|
||||
|
||||
export type LogoutOptions = MutationOptions<unknown, undefined>;
|
||||
|
||||
/* Assistant mutations */
|
||||
|
||||
export type AssistantAvatarVariables = {
|
||||
|
|
@ -331,3 +329,10 @@ export type EditArtifactOptions = MutationOptions<
|
|||
unknown,
|
||||
Error
|
||||
>;
|
||||
|
||||
export type TLogoutResponse = {
|
||||
message: string;
|
||||
redirect?: string;
|
||||
};
|
||||
|
||||
export type LogoutOptions = MutationOptions<TLogoutResponse, undefined>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue