first commit

This commit is contained in:
AyrisAI
2026-05-14 01:57:52 +03:00
parent 863a32cd35
commit 4a9196f483
47 changed files with 12043 additions and 102 deletions

View File

@@ -0,0 +1,49 @@
import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/auth";
import { getMailSession, setMailSession, clearMailSession } from "@/lib/mail-session";
import { listFolders } from "@/lib/imap";
// POST /api/mail/auth — login to mailbox (store creds in cookie)
export async function POST(req: NextRequest) {
const session = await auth();
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const { email, password } = await req.json();
if (!email || !password) {
return NextResponse.json({ error: "Email ve şifre gerekli" }, { status: 400 });
}
// Test the credentials by listing folders
try {
await listFolders({ email, password });
} catch (err: any) {
return NextResponse.json(
{ error: "IMAP bağlantısı başarısız: " + (err?.message ?? "Bilinmeyen hata") },
{ status: 401 }
);
}
await setMailSession({ email, password });
return NextResponse.json({ success: true, email });
}
// GET /api/mail/auth — check if mail session exists
export async function GET() {
const session = await auth();
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const mailSession = await getMailSession();
if (!mailSession) {
return NextResponse.json({ connected: false });
}
return NextResponse.json({ connected: true, email: mailSession.email });
}
// DELETE /api/mail/auth — logout from mailbox
export async function DELETE() {
const session = await auth();
if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
await clearMailSession();
return NextResponse.json({ success: true });
}