fosrl.pangolin/src/app/auth/login/page.tsx

71 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-10-13 14:50:07 -04:00
import { verifySession } from "@app/lib/auth/verifySession";
2024-10-19 16:37:40 -04:00
import Link from "next/link";
import { redirect } from "next/navigation";
import { cache } from "react";
import DashboardLoginForm from "./DashboardLoginForm";
2024-12-25 15:54:32 -05:00
import { Mail } from "lucide-react";
2025-01-04 20:22:01 -05:00
import { pullEnv } from "@app/lib/pullEnv";
import { cleanRedirect } from "@app/lib/cleanRedirect";
export const dynamic = "force-dynamic";
2024-10-06 09:55:45 -04:00
2024-11-02 23:46:08 -04:00
export default async function Page(props: {
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}) {
2024-10-23 13:30:23 -04:00
const searchParams = await props.searchParams;
const getUser = cache(verifySession);
const user = await getUser();
2024-10-06 09:55:45 -04:00
2024-12-25 15:54:32 -05:00
const isInvite = searchParams?.redirect?.includes("/invite");
2025-01-04 20:22:01 -05:00
const env = pullEnv();
const signUpDisabled = env.flags.disableSignupWithoutInvite;
2024-12-25 15:54:32 -05:00
if (user) {
redirect("/");
2024-10-06 09:55:45 -04:00
}
let redirectUrl: string | undefined = undefined;
if (searchParams.redirect) {
redirectUrl = cleanRedirect(searchParams.redirect as string);
}
2024-10-06 09:55:45 -04:00
return (
<>
2024-12-25 15:54:32 -05:00
{isInvite && (
<div className="border rounded-md p-3 mb-4">
<div className="flex flex-col items-center">
<Mail className="w-12 h-12 mb-4 text-primary" />
<h2 className="text-2xl font-bold mb-2 text-center">
Looks like you've been invited!
</h2>
<p className="text-center">
To accept the invite, you must login or create an
account.
</p>
</div>
</div>
)}
<DashboardLoginForm redirect={redirectUrl} />
2024-10-19 16:37:40 -04:00
2024-12-25 15:54:32 -05:00
{(!signUpDisabled || isInvite) && (
<p className="text-center text-muted-foreground mt-4">
Don't have an account?{" "}
<Link
href={
!redirectUrl
2024-12-25 15:54:32 -05:00
? `/auth/signup`
: `/auth/signup?redirect=${redirectUrl}`
2024-12-25 15:54:32 -05:00
}
className="underline"
>
Sign up
</Link>
</p>
)}
</>
2024-10-06 09:55:45 -04:00
);
}