24 lines
1.2 KiB
TypeScript
24 lines
1.2 KiB
TypeScript
import { redirect } from "next/navigation";
|
|
import { SiteHeader } from "@/components/public/site-header";
|
|
import { isAuthorizedAdmin } from "@/lib/auth/authorization";
|
|
import { getCustomerSession } from "@/lib/auth/server";
|
|
import { safeAuthReturnPath } from "@/lib/auth/return-path";
|
|
import { AccountForm } from "./account-form";
|
|
|
|
export async function AccountPage({ mode, next, verified, verificationError }: {
|
|
mode: "login" | "register"; next: unknown; verified?: boolean; verificationError?: boolean;
|
|
}) {
|
|
const nextPath = safeAuthReturnPath(next);
|
|
const session = await getCustomerSession();
|
|
if (session) {
|
|
if (nextPath.startsWith("/admin") && !isAuthorizedAdmin(session.user)) redirect("/");
|
|
redirect(nextPath);
|
|
}
|
|
const siteKey = process.env.TURNSTILE_SITE_KEY ?? "";
|
|
if (process.env.NODE_ENV !== "development" && !siteKey) throw new Error("TURNSTILE_SITE_KEY is required");
|
|
return <div className="min-h-svh"><SiteHeader /><main className="grid min-h-[calc(100svh-4rem)] place-items-center p-4">
|
|
<AccountForm mode={mode} siteKey={siteKey} nextPath={nextPath}
|
|
verified={verified} verificationError={verificationError} />
|
|
</main></div>;
|
|
}
|