fix(web):align shared session utilities

This commit is contained in:
Anish Sarkar 2026-06-24 03:59:27 +05:30
parent f98d874185
commit 83ee9aa7ea
2 changed files with 11 additions and 8 deletions

View file

@ -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}`);

View file

@ -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";