64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import { useSession } from "next-auth/react";
|
|
import { useRouter, useSearchParams } from "next/navigation";
|
|
import { useEffect, Suspense } from "react";
|
|
import NextAuthComponent from "@/app/components/NextAuthComponent";
|
|
|
|
import "../styles/new-site.css";
|
|
|
|
function deriveWorkspace(email: string): string {
|
|
return (
|
|
email
|
|
.split("@")[0]
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, "-") + "-account"
|
|
);
|
|
}
|
|
|
|
function AuthPageInner() {
|
|
const { data: session, status } = useSession();
|
|
const router = useRouter();
|
|
const searchParams = useSearchParams();
|
|
|
|
useEffect(() => {
|
|
if (status === "authenticated" && session?.user?.email) {
|
|
const workspace = deriveWorkspace(session.user.email);
|
|
router.push(`/${workspace}/projects`);
|
|
}
|
|
}, [status, session, router, searchParams]);
|
|
|
|
if (status === "loading") {
|
|
return (
|
|
<div className="justine-auth-inner">
|
|
<div className="justine-auth-loading-wrap">
|
|
<div className="justine-auth-spinner" aria-hidden />
|
|
<p className="justine-auth-loading-text">Loading authentication…</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div
|
|
className="new-site-wrapper"
|
|
style={{
|
|
display: "flex",
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
minHeight: "100vh",
|
|
}}
|
|
>
|
|
<NextAuthComponent />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function AuthPage() {
|
|
return (
|
|
<Suspense>
|
|
<AuthPageInner />
|
|
</Suspense>
|
|
);
|
|
}
|