Update features and dependencies
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import crypto from "node:crypto";
|
||||
import { z } from "zod";
|
||||
import { db, apiKeys, eq } from "@epicure/db";
|
||||
import { db, apiKeys, eq, sql } from "@epicure/db";
|
||||
import { requireSession } from "@/lib/api-auth";
|
||||
|
||||
const CreateApiKeyBody = z.object({
|
||||
@@ -38,6 +38,14 @@ export async function POST(req: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
const [row] = await db
|
||||
.select({ count: sql<number>`count(*)::int` })
|
||||
.from(apiKeys)
|
||||
.where(eq(apiKeys.userId, session!.user.id));
|
||||
if ((row?.count ?? 0) >= 10) {
|
||||
return NextResponse.json({ error: "API key limit reached (max 10)" }, { status: 403 });
|
||||
}
|
||||
|
||||
const rawKey = "ek_" + crypto.randomBytes(32).toString("hex");
|
||||
const keyHash = crypto.createHash("sha256").update(rawKey).digest("hex");
|
||||
const id = crypto.randomUUID();
|
||||
|
||||
Reference in New Issue
Block a user