add crm auth, email, status update and search
All checks were successful
Auto Deploy / deploy (push) Successful in 1m7s

This commit is contained in:
deonisii
2026-04-17 21:29:14 +03:00
parent 246fb6d52d
commit 4f67bca4be
16 changed files with 502 additions and 35 deletions

View File

@@ -0,0 +1,38 @@
import { NextResponse } from "next/server";
import { createSessionToken, getAdminCredentials, getSessionCookieName } from "@/lib/auth";
type LoginPayload = {
email?: string;
password?: string;
};
export async function POST(request: Request) {
try {
const body = (await request.json()) as LoginPayload;
const email = body.email?.trim().toLowerCase() || "";
const password = body.password?.trim() || "";
const admin = getAdminCredentials();
if (email !== admin.email.toLowerCase() || password !== admin.password) {
return NextResponse.json({ error: "Неверный email или пароль" }, { status: 401 });
}
const token = await createSessionToken(email);
const response = NextResponse.json({ success: true });
response.cookies.set({
name: getSessionCookieName(),
value: token,
httpOnly: true,
secure: true,
sameSite: "lax",
path: "/",
maxAge: 60 * 60 * 24 * 7,
});
return response;
} catch {
return NextResponse.json({ error: "Ошибка авторизации" }, { status: 500 });
}
}