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";
|
2024-10-06 18:08:26 -04:00
|
|
|
import { redirect } from "next/navigation";
|
2024-11-03 13:57:51 -05:00
|
|
|
import { cache } from "react";
|
2024-11-23 17:56:21 -05:00
|
|
|
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";
|
2025-01-09 23:21:57 -05:00
|
|
|
import { cleanRedirect } from "@app/lib/cleanRedirect";
|
2024-11-03 13:57:51 -05:00
|
|
|
|
2024-11-23 17:56:21 -05:00
|
|
|
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;
|
2024-11-03 13:57:51 -05:00
|
|
|
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
|
|
|
|
2024-10-06 18:08:26 -04:00
|
|
|
if (user) {
|
|
|
|
redirect("/");
|
2024-10-06 09:55:45 -04:00
|
|
|
}
|
|
|
|
|
2025-01-09 23:21:57 -05: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-10-06 18:08:26 -04:00
|
|
|
<>
|
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>
|
|
|
|
)}
|
|
|
|
|
2025-01-09 23:21:57 -05:00
|
|
|
<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={
|
2025-01-09 23:21:57 -05:00
|
|
|
!redirectUrl
|
2024-12-25 15:54:32 -05:00
|
|
|
? `/auth/signup`
|
2025-01-09 23:21:57 -05:00
|
|
|
: `/auth/signup?redirect=${redirectUrl}`
|
2024-12-25 15:54:32 -05:00
|
|
|
}
|
|
|
|
className="underline"
|
|
|
|
>
|
|
|
|
Sign up
|
|
|
|
</Link>
|
|
|
|
</p>
|
|
|
|
)}
|
2024-10-06 18:08:26 -04:00
|
|
|
</>
|
2024-10-06 09:55:45 -04:00
|
|
|
);
|
|
|
|
}
|