mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-12 08:42:18 +00:00
fix(ui): fall back when /v2/user/info returns a different user id
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
7f9cf5d182
commit
c98d454db9
2 changed files with 22 additions and 6 deletions
|
|
@ -330,6 +330,23 @@ describe("useUserLookup", () => {
|
|||
expect(result.current.data?.user_id).toBe("user-1-0");
|
||||
});
|
||||
|
||||
it("falls back when user info returns a different user id", async () => {
|
||||
const response = buildUserListResponse(1, 1);
|
||||
const exactUser = { ...response.users[0], user_id: "a b", user_alias: "Right User" };
|
||||
vi.mocked(userGetInfoV2).mockResolvedValue(buildUserInfoV2Response("a+b"));
|
||||
vi.mocked(userListCall).mockResolvedValue({
|
||||
...response,
|
||||
page_size: 100,
|
||||
users: [exactUser],
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useUserLookup("a b"), { wrapper });
|
||||
|
||||
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
||||
expect(result.current.data).toMatchObject({ user_id: "a b", user_alias: "Right User" });
|
||||
expect(userListCall).toHaveBeenCalledWith("test-access-token", ["a b"], 1, 100);
|
||||
});
|
||||
|
||||
it("falls back to the exact user list match when the user info endpoint returns a 404", async () => {
|
||||
const response = buildUserListResponse(1, 1);
|
||||
const exactUser = { ...response.users[1], user_id: "bob", user_alias: "Bob" };
|
||||
|
|
|
|||
|
|
@ -91,14 +91,13 @@ export const useUserLookup = (userId: string | null) => {
|
|||
queryKey: userLookupKeys.detail(userId ?? ""),
|
||||
queryFn: async () => {
|
||||
try {
|
||||
return mapUserInfoV2ToUserInfo(await userGetInfoV2(accessToken!, userId!));
|
||||
const user = await userGetInfoV2(accessToken!, userId!);
|
||||
if (user.user_id === userId) return mapUserInfoV2ToUserInfo(user);
|
||||
} catch (error) {
|
||||
if (error instanceof ApiError && error.status === 404) {
|
||||
const response = await userListCall(accessToken!, [userId!], 1, USER_LIST_MAX_PAGE_SIZE);
|
||||
return response.users.find((user) => user.user_id === userId) ?? null;
|
||||
}
|
||||
throw error;
|
||||
if (!(error instanceof ApiError && error.status === 404)) throw error;
|
||||
}
|
||||
const response = await userListCall(accessToken!, [userId!], 1, USER_LIST_MAX_PAGE_SIZE);
|
||||
return response.users.find((user) => user.user_id === userId) ?? null;
|
||||
},
|
||||
enabled: Boolean(accessToken) && Boolean(userId) && canListUsers(userRole),
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue