first commit

This commit is contained in:
2026-08-26 14:21:53 +03:00
commit fef66cd9dd
38 changed files with 5783 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import { NextRequest, NextResponse } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import sql from '@/lib/db'
import { randomBytes } from 'crypto'
export async function POST(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
const session = await getServerSession(authOptions)
if (!session) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
const { id } = await params
const newKey = randomBytes(32).toString('hex')
const [app] = await sql`
UPDATE apps SET api_key = ${newKey}
WHERE id = ${id}
RETURNING api_key
`
await sql`
INSERT INTO audit_logs (app_id, action, actor)
VALUES (${id}, 'rotate_key', ${session.user?.name ?? 'admin'})
`
return NextResponse.json({ api_key: app.api_key })
}