From 4ec4befeacaeb559aeaac38498fb85ff2e597d42 Mon Sep 17 00:00:00 2001 From: amianthus <49116958+SirTenzin@users.noreply.github.com> Date: Thu, 16 Apr 2026 16:12:59 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20address=20pr=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/website/components/hero.jsx | 16 ++++++++-- server/src/utils/auth.ts | 6 ++++ .../utils/authUtils/afterSessionDeleted.ts | 29 +++++++++++++++++++ vite/src/App.tsx | 4 +-- 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 server/src/utils/authUtils/afterSessionDeleted.ts diff --git a/apps/website/components/hero.jsx b/apps/website/components/hero.jsx index 360cb59d3..0688eff98 100755 --- a/apps/website/components/hero.jsx +++ b/apps/website/components/hero.jsx @@ -29,6 +29,12 @@ export default function Hero() { const containerRef = useRef(null); const heroTlRef = useRef(null); const [displayedText, setDisplayedText] = useState(""); + const [isLoggedIn, setIsLoggedIn] = useState(false); + + // Read the hint cookie after mount to avoid SSR/CSR hydration mismatch. + useEffect(() => { + setIsLoggedIn(getLoggedInHintCookie() === true); + }, []); // Badge typewriter useEffect(() => { @@ -208,7 +214,13 @@ export default function Hero() {
{/* Primary CTA */}
- + - {getLoggedInHintCookie() ? "Dashboard" : "Start for free"} + {isLoggedIn ? "Dashboard" : "Start for free"} diff --git a/server/src/utils/auth.ts b/server/src/utils/auth.ts index 0a166a023..1718a049d 100644 --- a/server/src/utils/auth.ts +++ b/server/src/utils/auth.ts @@ -20,6 +20,7 @@ import { sendOnboardingEmail } from "@/internal/emails/sendOnboardingEmail.js"; import sendOTPEmail from "@/internal/emails/sendOTPEmail.js"; import { afterOrgCreated } from "./authUtils/afterOrgCreated.js"; import { afterSessionCreated } from "./authUtils/afterSessionCreated.js"; +import { afterSessionDeleted } from "./authUtils/afterSessionDeleted.js"; import { beforeSessionCreated } from "./authUtils/beforeSessionCreated.js"; import { ADMIN_USER_IDs } from "./constants.js"; @@ -53,6 +54,11 @@ export const auth = betterAuth({ return afterSessionCreated(session, context); }, }, + delete: { + after: (session, context) => { + return afterSessionDeleted(session, context); + }, + }, }, }, user: { diff --git a/server/src/utils/authUtils/afterSessionDeleted.ts b/server/src/utils/authUtils/afterSessionDeleted.ts new file mode 100644 index 000000000..f7bf849f5 --- /dev/null +++ b/server/src/utils/authUtils/afterSessionDeleted.ts @@ -0,0 +1,29 @@ +import type { GenericEndpointContext } from "@better-auth/core"; +import type { BetterAuthOptions, Session } from "better-auth"; + +export const afterSessionDeleted = async ( + _session: Session, + context: GenericEndpointContext | null, +) => { + try { + if (!context) return; + + // Dev parity: the cookie is only set server-side in production, so + // we don't need to clear it here in other environments. + if (process.env.NODE_ENV !== "production") return; + + // Clear the landing-page hint cookie so signed-out users stop seeing + // the "Dashboard" CTA on useautumn.com. Attributes must match the + // original setCookie call so the browser overwrites the cookie. + context.setCookie("logged_in_hint", "", { + domain: ".useautumn.com", + path: "/", + maxAge: 0, + secure: true, + sameSite: "none", + httpOnly: false, + }); + } catch (_) { + console.error("Error running afterSessionDeleted", { error: _ }); + } +}; diff --git a/vite/src/App.tsx b/vite/src/App.tsx index 6c976f19a..c28ae0b34 100644 --- a/vite/src/App.tsx +++ b/vite/src/App.tsx @@ -59,11 +59,9 @@ export default function App() { document.cookie = "logged_in_hint=1; path=/; max-age=604800; SameSite=Lax"; } else { - document.cookie = - "logged_in_hint=; path=/; max-age=0; SameSite=Lax"; + document.cookie = "logged_in_hint=; path=/; max-age=0; SameSite=Lax"; } } - } } }, [data]); return (