35 lines
927 B
TypeScript
35 lines
927 B
TypeScript
import { redirect } from "next/navigation"
|
|
import { LoginForm } from "@/app/login/login-form"
|
|
import { resolveRoleFromServerContext } from "@/lib/access-server"
|
|
import { hasOwnerUser } from "@/lib/auth/server"
|
|
|
|
export const dynamic = "force-dynamic"
|
|
|
|
type SearchParams = Promise<Record<string, string | string[] | undefined>>
|
|
|
|
function getSingleValue(input: string | string[] | undefined): string | undefined {
|
|
if (Array.isArray(input)) {
|
|
return input[0]
|
|
}
|
|
|
|
return input
|
|
}
|
|
|
|
export default async function WelcomePage({ searchParams }: { searchParams: SearchParams }) {
|
|
const params = await searchParams
|
|
const nextPath = getSingleValue(params.next) ?? "/"
|
|
const role = await resolveRoleFromServerContext()
|
|
|
|
if (role) {
|
|
redirect("/")
|
|
}
|
|
|
|
const hasOwner = await hasOwnerUser()
|
|
|
|
if (hasOwner) {
|
|
redirect(`/login?next=${encodeURIComponent(nextPath)}`)
|
|
}
|
|
|
|
return <LoginForm mode="signup-owner" />
|
|
}
|