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:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user