feat(admin): add registration policy settings and disabled register state
This commit is contained in:
@@ -8,7 +8,7 @@ import { AdminLocaleSwitcher } from "@/components/admin-locale-switcher"
|
||||
import { useAdminT } from "@/providers/admin-i18n-provider"
|
||||
|
||||
type LoginFormProps = {
|
||||
mode: "signin" | "signup-owner" | "signup-user"
|
||||
mode: "signin" | "signup-owner" | "signup-user" | "signup-disabled"
|
||||
}
|
||||
|
||||
type AuthResponse = {
|
||||
@@ -41,6 +41,7 @@ export function LoginForm({ mode }: LoginFormProps) {
|
||||
const [isBusy, setIsBusy] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [success, setSuccess] = useState<string | null>(null)
|
||||
const canSubmitSignUp = mode === "signup-owner" || mode === "signup-user"
|
||||
|
||||
async function handleSignIn(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault()
|
||||
@@ -141,7 +142,9 @@ export function LoginForm({ mode }: LoginFormProps) {
|
||||
? t("auth.titles.signIn", "Sign in to CMS Admin")
|
||||
: mode === "signup-owner"
|
||||
? t("auth.titles.signUpOwner", "Welcome to CMS Admin")
|
||||
: t("auth.titles.signUpUser", "Create an admin account")}
|
||||
: mode === "signup-user"
|
||||
? t("auth.titles.signUpUser", "Create an admin account")
|
||||
: t("auth.titles.signUpDisabled", "Registration is disabled")}
|
||||
</h1>
|
||||
<p className="text-sm text-neutral-600">
|
||||
{mode === "signin"
|
||||
@@ -151,7 +154,12 @@ export function LoginForm({ mode }: LoginFormProps) {
|
||||
"auth.descriptions.signUpOwner",
|
||||
"Create the first owner account to initialize this admin instance.",
|
||||
)
|
||||
: t("auth.descriptions.signUpUser", "Self-registration is enabled for admin users.")}
|
||||
: mode === "signup-user"
|
||||
? t("auth.descriptions.signUpUser", "Self-registration is enabled for admin users.")
|
||||
: t(
|
||||
"auth.descriptions.signUpDisabled",
|
||||
"Self-registration is currently turned off by an administrator.",
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -208,7 +216,7 @@ export function LoginForm({ mode }: LoginFormProps) {
|
||||
|
||||
{error ? <p className="text-sm text-red-600">{error}</p> : null}
|
||||
</form>
|
||||
) : (
|
||||
) : canSubmitSignUp ? (
|
||||
<form
|
||||
onSubmit={handleSignUp}
|
||||
className="mt-8 space-y-4 rounded-xl border border-neutral-200 p-6"
|
||||
@@ -290,6 +298,20 @@ export function LoginForm({ mode }: LoginFormProps) {
|
||||
{error ? <p className="text-sm text-red-600">{error}</p> : null}
|
||||
{success ? <p className="text-sm text-green-700">{success}</p> : null}
|
||||
</form>
|
||||
) : (
|
||||
<section className="mt-8 space-y-4 rounded-xl border border-neutral-200 p-6">
|
||||
<p className="text-sm text-neutral-700">
|
||||
{t(
|
||||
"auth.messages.registrationDisabled",
|
||||
"Registration is disabled for this admin instance. Ask an administrator to create an account or enable self-registration.",
|
||||
)}
|
||||
</p>
|
||||
<p className="text-xs text-neutral-600">
|
||||
<Link href={`/login?next=${encodeURIComponent(nextPath)}`} className="underline">
|
||||
{t("auth.links.goToSignIn", "Go to sign in")}
|
||||
</Link>
|
||||
</p>
|
||||
</section>
|
||||
)}
|
||||
</main>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user