Files
image-apiv3/app/api/v1/api-keys/[id]/route.ts
Beyhan Oğur 031582ea2c first commit
2026-04-26 22:11:03 +03:00

39 lines
1.1 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 { NextRequest, NextResponse } from "next/server";
import { db } from "@/db";
import { apiKeys } from "@/db/schema";
import { and, eq } from "drizzle-orm";
import { authenticateWebOrAPIRequest } from "@/app/lib/api-auth";
/**
* DELETE /api/v1/api-keys/[id] — Kendi anahtarını iptal et (isActive: false)
*/
export async function DELETE(
request: NextRequest,
context: { params: Promise<{ id: string }> }
) {
const auth = await authenticateWebOrAPIRequest(request);
if (!auth.authenticated || !auth.userId) {
return NextResponse.json({ error: auth.error ?? "Yetkisiz" }, { status: 401 });
}
const { id } = await context.params;
const updated = await db
.update(apiKeys)
.set({ isActive: false, updatedAt: new Date() })
.where(and(eq(apiKeys.id, id), eq(apiKeys.userId, auth.userId)))
.returning({ id: apiKeys.id });
if (updated.length === 0) {
return NextResponse.json(
{ error: "Anahtar bulunamadı veya size ait değil." },
{ status: 404 }
);
}
return NextResponse.json({
success: true,
message: "API anahtarı iptal edildi.",
});
}