This commit is contained in:
2026-06-09 15:15:40 +03:00
parent f6b4acb760
commit d908d83ca5
58 changed files with 4320 additions and 419 deletions
+34
View File
@@ -0,0 +1,34 @@
"use server";
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
export type ActionState = { error: string } | null;
export async function login(prevState: ActionState, formData: FormData): Promise<ActionState> {
const username = formData.get("username");
const password = formData.get("password");
if (
username === process.env.ADMIN_USERNAME &&
password === process.env.ADMIN_PASSWORD
) {
const cookieStore = await cookies();
cookieStore.set("admin_session", "true", {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
maxAge: 60 * 60 * 24 * 7, // 1 week
path: "/",
});
} else {
return { error: "Geçersiz kullanıcı adı veya şifre" };
}
redirect("/admin");
}
export async function logout() {
const cookieStore = await cookies();
cookieStore.delete("admin_session");
redirect("/admin/login");
}