mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-16 09:56:36 +00:00
setup server admin
This commit is contained in:
@@ -3,6 +3,7 @@ import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import { cache } from "react";
|
||||
import DashboardLoginForm from "./DashboardLoginForm";
|
||||
import { Mail } from "lucide-react";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -13,27 +14,48 @@ export default async function Page(props: {
|
||||
const getUser = cache(verifySession);
|
||||
const user = await getUser();
|
||||
|
||||
const isInvite = searchParams?.redirect?.includes("/invite");
|
||||
|
||||
const signUpDisabled = process.env.DISABLE_SIGNUP_WITHOUT_INVITE === "true";
|
||||
|
||||
if (user) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{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={searchParams.redirect as string} />
|
||||
|
||||
<p className="text-center text-muted-foreground mt-4">
|
||||
Don't have an account?{" "}
|
||||
<Link
|
||||
href={
|
||||
!searchParams.redirect
|
||||
? `/auth/signup`
|
||||
: `/auth/signup?redirect=${searchParams.redirect}`
|
||||
}
|
||||
className="underline"
|
||||
>
|
||||
Sign up
|
||||
</Link>
|
||||
</p>
|
||||
{(!signUpDisabled || isInvite) && (
|
||||
<p className="text-center text-muted-foreground mt-4">
|
||||
Don't have an account?{" "}
|
||||
<Link
|
||||
href={
|
||||
!searchParams.redirect
|
||||
? `/auth/signup`
|
||||
: `/auth/signup?redirect=${searchParams.redirect}`
|
||||
}
|
||||
className="underline"
|
||||
>
|
||||
Sign up
|
||||
</Link>
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||
|
||||
type SignupFormProps = {
|
||||
redirect?: string;
|
||||
inviteId?: string;
|
||||
inviteToken?: string;
|
||||
};
|
||||
|
||||
const formSchema = z
|
||||
@@ -45,7 +47,7 @@ const formSchema = z
|
||||
message: "Passwords do not match",
|
||||
});
|
||||
|
||||
export default function SignupForm({ redirect }: SignupFormProps) {
|
||||
export default function SignupForm({ redirect, inviteId, inviteToken }: SignupFormProps) {
|
||||
const router = useRouter();
|
||||
|
||||
const api = createApiClient(useEnvContext());
|
||||
@@ -70,6 +72,8 @@ export default function SignupForm({ redirect }: SignupFormProps) {
|
||||
.put<AxiosResponse<SignUpResponse>>("/auth/signup", {
|
||||
email,
|
||||
password,
|
||||
inviteId,
|
||||
inviteToken
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
|
||||
@@ -1,25 +1,65 @@
|
||||
import SignupForm from "@app/app/auth/signup/SignupForm";
|
||||
import { verifySession } from "@app/lib/auth/verifySession";
|
||||
import { Mail } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import { cache } from "react";
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function Page(props: {
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
|
||||
searchParams: Promise<{ redirect: string | undefined }>;
|
||||
}) {
|
||||
const searchParams = await props.searchParams;
|
||||
const getUser = cache(verifySession);
|
||||
const user = await getUser();
|
||||
|
||||
const isInvite = searchParams?.redirect?.includes("/invite");
|
||||
|
||||
if (process.env.DISABLE_SIGNUP_WITHOUT_INVITE === "true" && !isInvite) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
if (user) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
let inviteId;
|
||||
let inviteToken;
|
||||
if (searchParams.redirect && isInvite) {
|
||||
const parts = searchParams.redirect.split("token=");
|
||||
if (parts.length) {
|
||||
const token = parts[1];
|
||||
const tokenParts = token.split("-");
|
||||
if (tokenParts.length === 2) {
|
||||
inviteId = tokenParts[0];
|
||||
inviteToken = tokenParts[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<SignupForm redirect={searchParams.redirect as string} />
|
||||
{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>
|
||||
)}
|
||||
|
||||
<SignupForm
|
||||
redirect={searchParams.redirect as string}
|
||||
inviteToken={inviteToken}
|
||||
inviteId={inviteId}
|
||||
/>
|
||||
|
||||
<p className="text-center text-muted-foreground mt-4">
|
||||
Already have an account?{" "}
|
||||
|
||||
Reference in New Issue
Block a user