From 3d5aaa9eadb597457053588ee88483b79d308538 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sat, 20 Dec 2025 13:29:51 +0100 Subject: [PATCH] feat: Align conditional fetching with conditional rendering for API Keys and Channels (#118) (#20043) Fixes #19967 Co-authored-by: Tim Baek Co-authored-by: Claude --- src/lib/components/chat/Settings/Account.svelte | 15 +++++++++++---- src/lib/components/layout/Sidebar.svelte | 8 +++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/lib/components/chat/Settings/Account.svelte b/src/lib/components/chat/Settings/Account.svelte index 7765f81f3..c47391a6e 100644 --- a/src/lib/components/chat/Settings/Account.svelte +++ b/src/lib/components/chat/Settings/Account.svelte @@ -109,10 +109,17 @@ webhookUrl = $settings?.notifications?.webhook_url ?? ''; - APIKey = await getAPIKey(localStorage.token).catch((error) => { - console.log(error); - return ''; - }); + // Only fetch API key if the feature is enabled and user has permission + if ( + user && + ($config?.features?.enable_api_keys ?? true) && + (user?.role === 'admin' || (user?.permissions?.features?.api_keys ?? false)) + ) { + APIKey = await getAPIKey(localStorage.token).catch((error) => { + console.log(error); + return ''; + }); + } loaded = true; }); diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 055970bc9..5e9ed83a2 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -455,7 +455,13 @@ } if (value) { - await initChannels(); + // Only fetch channels if the feature is enabled and user has permission + if ( + $config?.features?.enable_channels && + ($user?.role === 'admin' || ($user?.permissions?.features?.channels ?? true)) + ) { + await initChannels(); + } await initChatList(); } })