Open source CapCut alternative.
TypeScript
feat(site): require sign-in on the Cut app surface
David Leab2a3dc68563
diff --git a/site/src/app/cut/app/layout.tsx b/site/src/app/cut/app/layout.tsxindex 9a8c0516..79370303 100644--- a/site/src/app/cut/app/layout.tsx+++ b/site/src/app/cut/app/layout.tsx@@ -1,17 +1,20 @@import type { ReactNode } from "react";import { AppSurfaceBackground } from "@/app/app/_components/AppSurfaceBackground";+import { RequireSession } from "@/cut/components/RequireSession";// The Cut app (projects home, library, editor) renders on the same white// product surface as Donkey's /app, not the cream marketing background of the// landing page that lives one segment up. AppSurfaceBackground paints the root// html white so the cream does not show through the overscroll area, and-// font-system matches the /app system font stack.+// font-system matches the /app system font stack. RequireSession gates the+// whole subtree on a signed-in session, redirecting signed-out visitors to+// sign-in with their target URL as the callback.export default function CutAppLayout({ children }: { children: ReactNode }) {return (<div className="min-h-screen bg-white font-system text-foreground antialiased"><AppSurfaceBackground />- {children}+ <RequireSession>{children}</RequireSession></div>);}diff --git a/site/src/cut/components/RequireSession.tsx b/site/src/cut/components/RequireSession.tsxnew file mode 100644index 00000000..20930407--- /dev/null+++ b/site/src/cut/components/RequireSession.tsx@@ -0,0 +1,39 @@+"use client";++import { useEffect, type ReactNode } from "react";++import { signInHrefFor } from "@/app/_components/landing/useAppEntryHref";+import { DONKEYCUT_CANONICAL } from "@/cut/lib/hosts";+import { authClient } from "@/lib/auth-client";+import { useCutBase } from "@/cut/lib/nav";++// Session gate for the whole Cut app surface. The landing CTAs already route+// signed-out clicks through /sign-in (useAppEntryHref); this covers direct+// navigation to an app URL the same way, sending the visitor to sign-in with+// the URL they wanted as the post-auth callback. While the session is still+// resolving the app renders normally, so signed-in users (the common case) see+// no gate at all.+//+// The legacy host (base "") has no /sign-in of its own — donkeycut.com owns+// auth — so its URLs redirect to the canonical host, mapped onto the same app+// under /app. Project state lives in the local engine, so it survives the host+// move.+export function RequireSession({ children }: { children: ReactNode }) {+ const { data: session, isPending } = authClient.useSession();+ const base = useCutBase();++ const signedOut = !isPending && !session;++ useEffect(() => {+ if (!signedOut) return;+ const here = window.location.pathname + window.location.search;+ window.location.replace(+ base === ""+ ? `${DONKEYCUT_CANONICAL}${signInHrefFor(here === "/" ? "/app" : `/app${here}`)}`+ : signInHrefFor(here),+ );+ }, [signedOut, base]);++ if (signedOut) return null;+ return <>{children}</>;+}