diff --git a/surfsense_web/app/api/zero/query/route.ts b/surfsense_web/app/api/zero/query/route.ts index 98cd4551c..3d8ff0d33 100644 --- a/surfsense_web/app/api/zero/query/route.ts +++ b/surfsense_web/app/api/zero/query/route.ts @@ -12,7 +12,7 @@ async function authenticateRequest( ): Promise<{ ctx: Context; error?: never } | { ctx?: never; error: NextResponse }> { const authHeader = request.headers.get("Authorization"); if (!authHeader?.startsWith("Bearer ")) { - return { error: NextResponse.json({ error: "Unauthorized" }, { status: 401 }) }; + return { ctx: undefined }; } try { diff --git a/surfsense_web/components/providers/ZeroProvider.tsx b/surfsense_web/components/providers/ZeroProvider.tsx index cd35fc02d..f4df921f3 100644 --- a/surfsense_web/components/providers/ZeroProvider.tsx +++ b/surfsense_web/components/providers/ZeroProvider.tsx @@ -43,17 +43,23 @@ function ZeroAuthGuard({ children }: { children: React.ReactNode }) { export function ZeroProvider({ children }: { children: React.ReactNode }) { const { data: user } = useAtomValue(currentUserAtom); - if (!user?.id) { - return <>{children}; - } + const hasUser = !!user?.id; + const userID = hasUser ? String(user.id) : "anon"; + const context = hasUser ? { userId: String(user.id) } : undefined; + const auth = hasUser ? getBearerToken() || undefined : undefined; - const userID = String(user.id); - const context = { userId: userID }; - const auth = getBearerToken() || undefined; + const opts = { + userID, + schema, + queries, + context, + cacheURL, + auth, + }; return ( - - {children} + + {hasUser ? {children} : children} ); }