From dbd9a945b062ddf6e34d1582b9c4dd8929c3420e Mon Sep 17 00:00:00 2001 From: sabaimran Date: Fri, 18 Oct 2024 09:31:56 -0700 Subject: [PATCH] Re-evaluate agent private/public filtering after authenticateddata is retrieved. Update selectedAgent check logic to reflect. --- src/interface/web/app/agents/page.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/interface/web/app/agents/page.tsx b/src/interface/web/app/agents/page.tsx index 3a7ce172..45b485fb 100644 --- a/src/interface/web/app/agents/page.tsx +++ b/src/interface/web/app/agents/page.tsx @@ -1481,7 +1481,13 @@ export default function Agents() { // Search for the agent with the slug in the URL if (agentSlug) { setAgentSlug(agentSlug); - const selectedAgent = data.find((agent) => agent.slug === agentSlug); + let selectedAgent = data.find((agent) => agent.slug === agentSlug); + + // If the agent is not found in all the returned agents, check in the public agents. The code may be running 2x after either agent data or authenticated data is retrieved. + if (!selectedAgent) { + selectedAgent = publicAgents.find((agent) => agent.slug === agentSlug); + } + if (!selectedAgent) { // See if the agent is accessible as a protected agent. fetch(`/api/agents/${agentSlug}`) @@ -1500,7 +1506,7 @@ export default function Agents() { } } } - }, [data]); + }, [data, authenticatedData]); if (error) { return (