summaryrefslogtreecommitdiff
path: root/apps/web/app/api/v1
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-07 05:03:35 -0800
committerFuwn <[email protected]>2026-02-07 05:03:35 -0800
commit17f0f1877764e9c1d79a2b86dac8ff2110aa6a34 (patch)
tree1cabf70d230dc614c3ee2408bdc0acaf13a502d8 /apps/web/app/api/v1
parentfeat: dynamically compute sidebar max width from item text widths (diff)
downloadasa.news-17f0f1877764e9c1d79a2b86dac8ff2110aa6a34.tar.xz
asa.news-17f0f1877764e9c1d79a2b86dac8ff2110aa6a34.zip
fix: api key prefix rename, revoke fix, and webhook validation
Rename API key prefix from asn_ to asa_, fix key revoke by aligning response property names with frontend interface, and add server/client validation to prevent enabling webhooks without a URL.
Diffstat (limited to 'apps/web/app/api/v1')
-rw-r--r--apps/web/app/api/v1/keys/route.ts27
1 files changed, 16 insertions, 11 deletions
diff --git a/apps/web/app/api/v1/keys/route.ts b/apps/web/app/api/v1/keys/route.ts
index 1461532..de63a46 100644
--- a/apps/web/app/api/v1/keys/route.ts
+++ b/apps/web/app/api/v1/keys/route.ts
@@ -31,14 +31,15 @@ export async function GET() {
)
}
+ const activeKeys = keys.filter((key) => key.revoked_at === null)
+
return NextResponse.json({
- keys: keys.map((key) => ({
- identifier: key.id,
+ keys: activeKeys.map((key) => ({
+ keyIdentifier: key.id,
keyPrefix: key.key_prefix,
label: key.label,
createdAt: key.created_at,
lastUsedAt: key.last_used_at,
- isRevoked: key.revoked_at !== null,
})),
})
}
@@ -94,12 +95,16 @@ export async function POST(request: Request) {
const { fullKey, keyHash, keyPrefix } = generateApiKey()
- const { error: insertError } = await adminClient.from("api_keys").insert({
- user_id: user.id,
- key_hash: keyHash,
- key_prefix: keyPrefix,
- label,
- })
+ const { data: insertedKey, error: insertError } = await adminClient
+ .from("api_keys")
+ .insert({
+ user_id: user.id,
+ key_hash: keyHash,
+ key_prefix: keyPrefix,
+ label,
+ })
+ .select("id")
+ .single()
if (insertError) {
return NextResponse.json(
@@ -109,8 +114,8 @@ export async function POST(request: Request) {
}
return NextResponse.json({
- key: fullKey,
+ fullKey,
keyPrefix,
- label,
+ keyIdentifier: insertedKey.id,
})
}