feat: Implement first admin setup guard to lock registration after initial account creation

- Updated the registration flow to check if the first admin account has been created, preventing further public registrations.
- Introduced `is_first_admin_setup_available` function to determine registration availability.
- Modified the `/register` and `/login` pages to redirect based on the setup state.
- Enhanced the user creation process to handle internal admin accounts correctly.
- Added migration script to enforce the new registration rules in the database.
- Refactored chat API to improve message handling and context building.
- Updated dashboard and settings components for better state management.
- Improved error handling and user feedback across various components.
This commit is contained in:
Poyraz Avsever
2026-06-08 16:22:26 +03:00
parent cf8492db9e
commit 950522d467
15 changed files with 570 additions and 445 deletions
+20 -4
View File
@@ -1,8 +1,10 @@
import { signup } from "@/app/login/actions";
import { AuthPageShell } from "@/components/auth/auth-page-shell";
import { ErrorToaster } from "@/components/error-toaster";
import { LockKeyhole, Mail, Search, UserPlus } from "lucide-react";
import { getFirstAdminSetupState } from "@/lib/auth/first-admin-setup";
import { LockKeyhole, Mail, UserPlus } from "lucide-react";
import Link from "next/link";
import { redirect } from "next/navigation";
import { Button, Input, Label } from "poyraz-ui/atoms";
export default async function RegisterPage({
@@ -10,6 +12,20 @@ export default async function RegisterPage({
}: {
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}) {
const setupState = await getFirstAdminSetupState();
if (setupState.errorMessage) {
redirect(`/login?error=true&message=${encodeURIComponent(setupState.errorMessage)}`);
}
if (!setupState.available) {
redirect(
`/login?error=true&message=${encodeURIComponent(
"Kayıt kapalı. Bu self-host kurulumunda ilk admin hesabı zaten oluşturulmuş.",
)}`,
);
}
const resolvedParams = await searchParams;
const error = resolvedParams?.error;
const message = resolvedParams?.message;
@@ -18,8 +34,8 @@ export default async function RegisterPage({
<>
{error && message && <ErrorToaster message={String(message)} />}
<AuthPageShell
title="Kayıt ol"
description="Freelancer operasyon panelini kullanmak için hesabını oluştur."
title="İlk admin hesabını oluştur"
description="Bu self-host kurulumu için Cognis çalışma alanının ilk yönetici hesabını oluştur."
form={
<form className="space-y-6">
<div className="space-y-4">
@@ -55,7 +71,7 @@ export default async function RegisterPage({
<Button formAction={signup} className="h-11 w-full gap-2">
<UserPlus className="h-4 w-4" />
Hesap oluştur
Admin hesabını oluştur
</Button>
</form>
}