From 83ee9aa7eaa06799fb67f5a82b2c77d926e4ff50 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Wed, 24 Jun 2026 03:59:27 +0530 Subject: [PATCH] fix(web):align shared session utilities --- .../public-chat/public-chat-footer.tsx | 17 ++++++++++------- .../settings/general-settings-manager.tsx | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/surfsense_web/components/public-chat/public-chat-footer.tsx b/surfsense_web/components/public-chat/public-chat-footer.tsx index 7d3263341..038ba37d5 100644 --- a/surfsense_web/components/public-chat/public-chat-footer.tsx +++ b/surfsense_web/components/public-chat/public-chat-footer.tsx @@ -6,8 +6,8 @@ import { useCallback, useEffect, useRef, useState } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Spinner } from "@/components/ui/spinner"; +import { useSession } from "@/hooks/use-session"; import { publicChatApiService } from "@/lib/apis/public-chat-api.service"; -import { getBearerToken } from "@/lib/auth-utils"; interface PublicChatFooterProps { shareToken: string; @@ -15,6 +15,7 @@ interface PublicChatFooterProps { export function PublicChatFooter({ shareToken }: PublicChatFooterProps) { const router = useRouter(); + const session = useSession(); const [isCloning, setIsCloning] = useState(false); const hasAutoCloned = useRef(false); @@ -40,19 +41,21 @@ export function PublicChatFooter({ shareToken }: PublicChatFooterProps) { // this is a one-time post-login check. (Vercel Best Practice: rerender-defer-reads 5.2) useEffect(() => { const action = new URLSearchParams(window.location.search).get("action"); - const token = getBearerToken(); // Only auto-clone once, if authenticated and action=clone is present - if (action === "clone" && token && !hasAutoCloned.current && !isCloning) { + if ( + action === "clone" && + session.authenticated && + !hasAutoCloned.current && + !isCloning + ) { hasAutoCloned.current = true; triggerClone(); } - }, [isCloning, triggerClone]); + }, [isCloning, session.authenticated, triggerClone]); const handleCopyAndContinue = async () => { - const token = getBearerToken(); - - if (!token) { + if (!session.authenticated) { // Include action=clone in the returnUrl so it persists after login const returnUrl = encodeURIComponent(`/public/${shareToken}?action=clone`); router.push(`/login?returnUrl=${returnUrl}`); diff --git a/surfsense_web/components/settings/general-settings-manager.tsx b/surfsense_web/components/settings/general-settings-manager.tsx index cfbcedbbf..9205f3bbe 100644 --- a/surfsense_web/components/settings/general-settings-manager.tsx +++ b/surfsense_web/components/settings/general-settings-manager.tsx @@ -15,7 +15,7 @@ import { Label } from "@/components/ui/label"; import { Skeleton } from "@/components/ui/skeleton"; import { Switch } from "@/components/ui/switch"; import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service"; -import { authenticatedFetch } from "@/lib/auth-utils"; +import { authenticatedFetch } from "@/lib/auth-fetch"; import { buildBackendUrl } from "@/lib/env-config"; import { cacheKeys } from "@/lib/query-client/cache-keys"; import { Spinner } from "../ui/spinner";