Files
mstfyldz/app/api/admin/login/route.ts
T
2026-08-16 17:18:23 +03:00

41 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NextResponse } from "next/server";
import { validateCredentials, createSessionToken, COOKIE_NAME } from "@/lib/auth";
export async function POST(request: Request) {
try {
const { username, password } = await request.json();
if (!validateCredentials(username, password)) {
return NextResponse.json(
{ error: "Kullanıcı adı veya şifre hatalı!" },
{ status: 401 }
);
}
const token = createSessionToken(username);
const response = NextResponse.json({
success: true,
message: "Giriş başarılı",
username,
});
response.cookies.set({
name: COOKIE_NAME,
value: token,
httpOnly: true,
secure: process.env.NODE_ENV === "production",
sameSite: "lax",
path: "/",
maxAge: 7 * 24 * 60 * 60, // 7 days
});
return response;
} catch (error) {
console.error("Login error:", error);
return NextResponse.json(
{ error: "Giriş işlemi sırasında sunucu hatası oluştu" },
{ status: 500 }
);
}
}