From 0561a78bc9341c19c487119a3a0fce7b23847a36 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Wed, 10 Sep 2025 07:17:36 -0500 Subject: [PATCH] ensure anonymous user always returns all cameras --- web/src/hooks/use-allowed-cameras.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/web/src/hooks/use-allowed-cameras.ts b/web/src/hooks/use-allowed-cameras.ts index bd4b25c49..9eae59fc2 100644 --- a/web/src/hooks/use-allowed-cameras.ts +++ b/web/src/hooks/use-allowed-cameras.ts @@ -1,7 +1,22 @@ import { useContext } from "react"; import { AuthContext } from "@/context/auth-context"; +import useSWR from "swr"; +import { FrigateConfig } from "@/types/frigateConfig"; export function useAllowedCameras() { const { auth } = useContext(AuthContext); - return auth.allowedCameras; + const { data: config } = useSWR("config", { + revalidateOnFocus: false, + }); + + if ( + auth.user?.role === "viewer" || + auth.user?.role === "admin" || + !auth.isAuthenticated // anonymous port 5000 + ) { + // return all cameras + return config?.cameras ? Object.keys(config.cameras) : []; + } + + return auth.allowedCameras || []; }