frontend: kullanıcı yönetimi sayfası

/users: kullanıcı listesi, ekleme formu, silme (kendi hesabını veya
son kalan tek kullanıcıyı silmeye izin verilmiyor). Nav'a link eklendi.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-01 12:28:19 +03:00
co-authored by Claude Sonnet 5
parent 783125b8f2
commit 5fef7460cf
3 changed files with 102 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
"use server";
import bcrypt from "bcryptjs";
import { prisma } from "@streamclipper/db";
import { revalidatePath } from "next/cache";
import { getSession } from "../../lib/auth";
export async function addUser(formData: FormData) {
const username = String(formData.get("username") ?? "").trim();
const password = String(formData.get("password") ?? "");
if (!username || password.length < 8) {
throw new Error("Kullanıcı adı gerekli, şifre en az 8 karakter olmalı.");
}
const passwordHash = await bcrypt.hash(password, 12);
await prisma.user.create({ data: { username, passwordHash } });
revalidatePath("/users");
}
export async function deleteUser(userId: string) {
const session = await getSession();
if (session?.sub === userId) {
throw new Error("Kendi hesabını silemezsin.");
}
const totalUsers = await prisma.user.count();
if (totalUsers <= 1) {
throw new Error("Son kalan kullanıcı silinemez.");
}
await prisma.user.delete({ where: { id: userId } });
revalidatePath("/users");
}