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
This commit is contained in:
2026-03-16 21:39:19 -07:00
parent 63dded42a6
commit 317abf047b
2 changed files with 10 additions and 5 deletions

View File

@@ -5,22 +5,27 @@ import { useRouter, useSearchParams } from "next/navigation";
import { useEffect, Suspense } from "react"; import { useEffect, Suspense } from "react";
import NextAuthComponent from "@/app/components/NextAuthComponent"; import NextAuthComponent from "@/app/components/NextAuthComponent";
function deriveWorkspace(email: string): string {
return email.split("@")[0].toLowerCase().replace(/[^a-z0-9]+/g, "-") + "-account";
}
function AuthPageInner() { function AuthPageInner() {
const { status } = useSession(); const { data: session, status } = useSession();
const router = useRouter(); const router = useRouter();
const searchParams = useSearchParams(); const searchParams = useSearchParams();
useEffect(() => { useEffect(() => {
if (status === "authenticated") { if (status === "authenticated" && session?.user?.email) {
const callbackUrl = searchParams.get("callbackUrl"); const callbackUrl = searchParams.get("callbackUrl");
// Only follow external callbackUrls we control (Theia subdomain) // Only follow external callbackUrls we control (Theia subdomain)
if (callbackUrl && callbackUrl.startsWith("https://theia.vibnai.com")) { if (callbackUrl && callbackUrl.startsWith("https://theia.vibnai.com")) {
window.location.href = callbackUrl; window.location.href = callbackUrl;
} else { } 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") { if (status === "loading") {
return ( return (

View File

@@ -13,7 +13,7 @@ export default function NextAuthComponent() {
try { try {
// Sign in with Google using NextAuth // Sign in with Google using NextAuth
await signIn("google", { await signIn("google", {
callbackUrl: "/marks-account/projects", callbackUrl: "/auth",
}); });
} catch (error) { } catch (error) {
console.error("Google sign-in error:", error); console.error("Google sign-in error:", error);