first commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user