From 317abf047b1b14db12e93d281ee1de217f2491f8 Mon Sep 17 00:00:00 2001 From: Mark Henderson Date: Mon, 16 Mar 2026 21:39:19 -0700 Subject: [PATCH] Fix auth redirect to use session email instead of hardcoded workspace New users were being sent to /marks-account/projects. Now derives workspace from the signed-in user's email so everyone lands on their own workspace after Google OAuth. Made-with: Cursor --- app/auth/page.tsx | 13 +++++++++---- app/components/NextAuthComponent.tsx | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/auth/page.tsx b/app/auth/page.tsx index 3674d76..1d9c671 100644 --- a/app/auth/page.tsx +++ b/app/auth/page.tsx @@ -5,22 +5,27 @@ import { useRouter, useSearchParams } from "next/navigation"; import { useEffect, Suspense } from "react"; import NextAuthComponent from "@/app/components/NextAuthComponent"; +function deriveWorkspace(email: string): string { + return email.split("@")[0].toLowerCase().replace(/[^a-z0-9]+/g, "-") + "-account"; +} + function AuthPageInner() { - const { status } = useSession(); + const { data: session, status } = useSession(); const router = useRouter(); const searchParams = useSearchParams(); useEffect(() => { - if (status === "authenticated") { + if (status === "authenticated" && session?.user?.email) { const callbackUrl = searchParams.get("callbackUrl"); // Only follow external callbackUrls we control (Theia subdomain) if (callbackUrl && callbackUrl.startsWith("https://theia.vibnai.com")) { window.location.href = callbackUrl; } else { - router.push("/marks-account/projects"); + const workspace = deriveWorkspace(session.user.email); + router.push(`/${workspace}/projects`); } } - }, [status, router, searchParams]); + }, [status, session, router, searchParams]); if (status === "loading") { return ( diff --git a/app/components/NextAuthComponent.tsx b/app/components/NextAuthComponent.tsx index a19c7a2..e0af278 100644 --- a/app/components/NextAuthComponent.tsx +++ b/app/components/NextAuthComponent.tsx @@ -13,7 +13,7 @@ export default function NextAuthComponent() { try { // Sign in with Google using NextAuth await signIn("google", { - callbackUrl: "/marks-account/projects", + callbackUrl: "/auth", }); } catch (error) { console.error("Google sign-in error:", error);