mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-26 21:39:43 +02:00
fix(web):align shared session utilities
This commit is contained in:
parent
f98d874185
commit
83ee9aa7ea
2 changed files with 11 additions and 8 deletions
|
|
@ -6,8 +6,8 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Spinner } from "@/components/ui/spinner";
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
|
import { useSession } from "@/hooks/use-session";
|
||||||
import { publicChatApiService } from "@/lib/apis/public-chat-api.service";
|
import { publicChatApiService } from "@/lib/apis/public-chat-api.service";
|
||||||
import { getBearerToken } from "@/lib/auth-utils";
|
|
||||||
|
|
||||||
interface PublicChatFooterProps {
|
interface PublicChatFooterProps {
|
||||||
shareToken: string;
|
shareToken: string;
|
||||||
|
|
@ -15,6 +15,7 @@ interface PublicChatFooterProps {
|
||||||
|
|
||||||
export function PublicChatFooter({ shareToken }: PublicChatFooterProps) {
|
export function PublicChatFooter({ shareToken }: PublicChatFooterProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const session = useSession();
|
||||||
const [isCloning, setIsCloning] = useState(false);
|
const [isCloning, setIsCloning] = useState(false);
|
||||||
const hasAutoCloned = useRef(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)
|
// this is a one-time post-login check. (Vercel Best Practice: rerender-defer-reads 5.2)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const action = new URLSearchParams(window.location.search).get("action");
|
const action = new URLSearchParams(window.location.search).get("action");
|
||||||
const token = getBearerToken();
|
|
||||||
|
|
||||||
// Only auto-clone once, if authenticated and action=clone is present
|
// 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;
|
hasAutoCloned.current = true;
|
||||||
triggerClone();
|
triggerClone();
|
||||||
}
|
}
|
||||||
}, [isCloning, triggerClone]);
|
}, [isCloning, session.authenticated, triggerClone]);
|
||||||
|
|
||||||
const handleCopyAndContinue = async () => {
|
const handleCopyAndContinue = async () => {
|
||||||
const token = getBearerToken();
|
if (!session.authenticated) {
|
||||||
|
|
||||||
if (!token) {
|
|
||||||
// Include action=clone in the returnUrl so it persists after login
|
// Include action=clone in the returnUrl so it persists after login
|
||||||
const returnUrl = encodeURIComponent(`/public/${shareToken}?action=clone`);
|
const returnUrl = encodeURIComponent(`/public/${shareToken}?action=clone`);
|
||||||
router.push(`/login?returnUrl=${returnUrl}`);
|
router.push(`/login?returnUrl=${returnUrl}`);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import { Label } from "@/components/ui/label";
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service";
|
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 { buildBackendUrl } from "@/lib/env-config";
|
||||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||||
import { Spinner } from "../ui/spinner";
|
import { Spinner } from "../ui/spinner";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue