diff --git a/src/lib/apis/users/index.ts b/src/lib/apis/users/index.ts index 85f5f2252..be82454c2 100644 --- a/src/lib/apis/users/index.ts +++ b/src/lib/apis/users/index.ts @@ -166,6 +166,34 @@ export const getUsers = async ( return res; }; +export const getAllUsers = async (token: string) => { + let error = null; + let res = null; + + res = await fetch(`${WEBUI_API_BASE_URL}/users/all`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .catch((err) => { + console.log(err); + error = err.detail; + return null; + }); + + if (error) { + throw error; + } + + return res; +}; + export const getUserSettings = async (token: string) => { let error = null; const res = await fetch(`${WEBUI_API_BASE_URL}/users/user/settings`, { diff --git a/src/lib/components/admin/Users/Groups.svelte b/src/lib/components/admin/Users/Groups.svelte index 36c1014ba..e89b463b0 100644 --- a/src/lib/components/admin/Users/Groups.svelte +++ b/src/lib/components/admin/Users/Groups.svelte @@ -23,13 +23,18 @@ import GroupItem from './Groups/GroupItem.svelte'; import AddGroupModal from './Groups/AddGroupModal.svelte'; import { createNewGroup, getGroups } from '$lib/apis/groups'; - import { getUserDefaultPermissions, updateUserDefaultPermissions } from '$lib/apis/users'; + import { + getUserDefaultPermissions, + getAllUsers, + updateUserDefaultPermissions + } from '$lib/apis/users'; const i18n = getContext('i18n'); let loaded = false; - export let users = []; + let users = []; + let total = 0; let groups = []; let filteredGroups; @@ -118,10 +123,22 @@ onMount(async () => { if ($user?.role !== 'admin') { await goto('/'); - } else { - await setGroups(); - defaultPermissions = await getUserDefaultPermissions(localStorage.token); + return; } + + const res = await getAllUsers(localStorage.token).catch((error) => { + toast.error(`${error}`); + return null; + }); + + if (res) { + users = res.users; + total = res.total; + } + + await setGroups(); + defaultPermissions = await getUserDefaultPermissions(localStorage.token); + loaded = true; });