Skip to content

Open source CapCut alternative.

TypeScript

fix(site): auth links stay clean for the default /app target

David Le790b7b93cf34
diff --git a/site/src/app/_components/landing/useAppEntryHref.ts b/site/src/app/_components/landing/useAppEntryHref.ts
index 0036a13f..93482b63 100644
--- a/site/src/app/_components/landing/useAppEntryHref.ts
+++ b/site/src/app/_components/landing/useAppEntryHref.ts
@@ -2,18 +2,21 @@
import { authClient } from "@/lib/auth-client";
-// Sign-in lives at the root-level /sign-in on the auth-owning host (donkeycut.com
-// owns auth directly), and the AuthScreen there already offers a "Create account"
-// toggle — so one sign-in link covers both "log in" and "sign up". The app target
-// (already root-prefixed for the host) rides along as the post-auth callback.
-export function signInHrefFor(appTarget: string): string {
- return `/sign-in?callbackURL=${encodeURIComponent(appTarget)}`;
-}
+// AuthScreen's post-auth fallback when no callbackURL rides the query string.
+// Targets equal to it need no param, keeping the common auth URLs clean.
+const DEFAULT_APP_TARGET = "/app";
-// Sign-up mirror of signInHrefFor; the auth screens read callbackURL from the
-// query string in either mode.
-export function signUpHrefFor(appTarget: string): string {
- return `/sign-up?callbackURL=${encodeURIComponent(appTarget)}`;
+// The auth screens live at root-level /sign-in and /sign-up on the auth-owning
+// host (donkeycut.com owns auth directly) and read callbackURL in either mode.
+// The app target (already root-prefixed for the host) rides along as the
+// post-auth callback.
+export function authHrefFor(
+ page: "/sign-in" | "/sign-up",
+ appTarget: string,
+): string {
+ return appTarget === DEFAULT_APP_TARGET
+ ? page
+ : `${page}?callbackURL=${encodeURIComponent(appTarget)}`;
}
// Where a landing CTA should actually go: straight into the app when signed in,
@@ -23,5 +26,5 @@ export function signUpHrefFor(appTarget: string): string {
export function useAppEntryHref(): (appTarget: string) => string {
const { data: session, isPending } = authClient.useSession();
return (appTarget: string) =>
- isPending || session ? appTarget : signInHrefFor(appTarget);
+ isPending || session ? appTarget : authHrefFor("/sign-in", appTarget);
}
diff --git a/site/src/app/cut/_components/landing/CutTopNav.tsx b/site/src/app/cut/_components/landing/CutTopNav.tsx
index 06e705a3..44d1f91d 100644
--- a/site/src/app/cut/_components/landing/CutTopNav.tsx
+++ b/site/src/app/cut/_components/landing/CutTopNav.tsx
@@ -1,10 +1,7 @@
"use client";
import { TopNav } from "@/app/_components/landing/TopNav";
-import {
- signInHrefFor,
- signUpHrefFor,
-} from "@/app/_components/landing/useAppEntryHref";
+import { authHrefFor } from "@/app/_components/landing/useAppEntryHref";
// The donkeycut.com site nav: Donkey Cut wordmark with session-aware auth
// entries. Shared by the Cut landing and the pass-through pages (e.g.
@@ -17,8 +14,8 @@ export function CutTopNav({ root }: { root: string }) {
wordmark="Donkey Cut"
signedInPill={{ href: `${root}/app`, label: "Go to App" }}
signedOutAuth={{
- logInHref: signInHrefFor(`${root}/app`),
- signUpHref: signUpHrefFor(`${root}/app`),
+ logInHref: authHrefFor("/sign-in", `${root}/app`),
+ signUpHref: authHrefFor("/sign-up", `${root}/app`),
}}
/>
);
diff --git a/site/src/cut/components/RequireSession.tsx b/site/src/cut/components/RequireSession.tsx
index 8b4dc189..f3b4400a 100644
--- a/site/src/cut/components/RequireSession.tsx
+++ b/site/src/cut/components/RequireSession.tsx
@@ -2,7 +2,7 @@
import { useEffect, type ReactNode } from "react";
-import { signInHrefFor } from "@/app/_components/landing/useAppEntryHref";
+import { authHrefFor } from "@/app/_components/landing/useAppEntryHref";
import { setEngineUser } from "@/cut/lib/api";
import { syncAccountFlags } from "@/cut/lib/flags";
import { DONKEYCUT_CANONICAL } from "@/cut/lib/hosts";
@@ -47,8 +47,8 @@ export function RequireSession({ children }: { children: ReactNode }) {
const here = window.location.pathname + window.location.search;
window.location.replace(
base === ""
- ? `${DONKEYCUT_CANONICAL}${signInHrefFor(here === "/" ? "/app" : `/app${here}`)}`
- : signInHrefFor(here),
+ ? `${DONKEYCUT_CANONICAL}${authHrefFor("/sign-in", here === "/" ? "/app" : `/app${here}`)}`
+ : authHrefFor("/sign-in", here),
);
}, [signedOut, base]);