From edc5f379d38413fb0903958cd5353d57f5ebd7ec Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Wed, 7 Jan 2026 18:33:32 +0200 Subject: [PATCH] auto-redirect only for single search space users --- surfsense_web/app/dashboard/page.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/surfsense_web/app/dashboard/page.tsx b/surfsense_web/app/dashboard/page.tsx index d343a28e3..22a2307f9 100644 --- a/surfsense_web/app/dashboard/page.tsx +++ b/surfsense_web/app/dashboard/page.tsx @@ -174,18 +174,22 @@ const DashboardPage = () => { const { data: user, isPending: isLoadingUser, error: userError } = useAtomValue(currentUserAtom); - // Auto-redirect to chat or auto-create search space + // Auto-redirect to chat for users with exactly 1 search space, or auto-create if none useEffect(() => { const handleAutoRedirect = async () => { // Don't run if still loading or already attempted if (loading || hasAttemptedAutoCreate.current) return; - // If user has search spaces, redirect to the first one's chat - if (searchSpaces.length > 0) { + // If user has exactly 1 search space, redirect to its chat + if (searchSpaces.length === 1) { router.replace(`/dashboard/${searchSpaces[0].id}/new-chat`); return; } + if (searchSpaces.length > 1) { + return; + } + // If no search spaces exist (edge case for users who registered before this feature), // auto-create one and redirect hasAttemptedAutoCreate.current = true; @@ -215,8 +219,8 @@ const DashboardPage = () => { avatar: "/icon-128.png", // Default avatar }; - // Show loading while loading, auto-redirecting, or auto-creating - if (loading || isAutoCreating || (searchSpaces.length > 0 && !error)) return ; + // Show loading while loading, auto-redirecting (single search space), or auto-creating + if (loading || isAutoCreating || (searchSpaces.length === 1 && !error)) return ; if (error) return ; const handleDeleteSearchSpace = async (id: number) => {