Re-evaluate agent private/public filtering after authenticateddata is retrieved. Update selectedAgent check logic to reflect.

This commit is contained in:
sabaimran 2024-10-18 09:31:56 -07:00
parent 35015e720e
commit dbd9a945b0

View file

@ -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 (