sanch1tx commited on
Commit
69177d5
·
verified ·
1 Parent(s): b0878b0

Update app/api/api-keys/route.ts

Browse files
Files changed (1) hide show
  1. app/api/api-keys/route.ts +6 -0
app/api/api-keys/route.ts CHANGED
@@ -4,6 +4,7 @@ import { db } from '@/lib/db';
4
  import { apiKeysTable, usersTable } from '@/lib/db/schema';
5
  import { eq, desc } from 'drizzle-orm';
6
  import { generateApiKey } from '@/lib/utils/api-key-generator';
 
7
 
8
  // Helper to authenticate user
9
  async function getAuthenticatedUser(req: NextRequest) {
@@ -87,8 +88,13 @@ export async function POST(req: NextRequest) {
87
  const keyName = body.name || 'Default API Key';
88
 
89
  const keyValue = generateApiKey();
 
 
 
 
90
 
91
  const [newKey] = await db.insert(apiKeysTable).values({
 
92
  keyValue,
93
  userId: user.uid,
94
  keyName,
 
4
  import { apiKeysTable, usersTable } from '@/lib/db/schema';
5
  import { eq, desc } from 'drizzle-orm';
6
  import { generateApiKey } from '@/lib/utils/api-key-generator';
7
+ import { nanoid } from 'nanoid'; // Import nanoid or similar for ID generation if UUID package isn't available
8
 
9
  // Helper to authenticate user
10
  async function getAuthenticatedUser(req: NextRequest) {
 
88
  const keyName = body.name || 'Default API Key';
89
 
90
  const keyValue = generateApiKey();
91
+
92
+ // Generate a unique ID for the API key entry
93
+ // Using nanoid or crypto.randomUUID() if available in environment
94
+ const id = crypto.randomUUID();
95
 
96
  const [newKey] = await db.insert(apiKeysTable).values({
97
+ id, // Explicitly provide ID
98
  keyValue,
99
  userId: user.uid,
100
  keyName,