feat: ability to delete api keys

This commit is contained in:
2026-06-02 22:16:49 +00:00
parent a0f84ec78e
commit 5b79f5fb4b
3 changed files with 10 additions and 11 deletions
+3 -4
View File
@@ -1743,13 +1743,12 @@ def update_api_key(kid: int):
@app.route("/api/api-keys/<int:kid>", methods=["DELETE"]) @app.route("/api/api-keys/<int:kid>", methods=["DELETE"])
@require_login @require_login
def revoke_api_key(kid: int): def delete_api_key(kid: int):
with db_cursor() as (_, cur): with db_cursor() as (_, cur):
cur.execute( cur.execute(
""" """
UPDATE api_keys DELETE FROM api_keys
SET revoked_at = CURRENT_TIMESTAMP WHERE id = %s
WHERE id = %s AND revoked_at IS NULL
""", """,
(kid,), (kid,),
) )
+6 -6
View File
@@ -366,14 +366,14 @@ async function submitApiKey() {
} }
} }
async function revokeApiKey(id: number, label: string) { async function deleteApiKey(id: number, label: string) {
if (!confirm(`Revoke API key "${label}"? This cannot be undone.`)) return; if (!confirm(`Delete API key "${label}"? This cannot be undone.`)) return;
apiKeysErr.value = ""; apiKeysErr.value = "";
try { try {
await api.revokeApiKey(id); await api.deleteApiKey(id);
await refreshApiKeys(); await refreshApiKeys();
} catch (e) { } catch (e) {
apiKeysErr.value = e instanceof Error ? e.message : "Failed to revoke API key"; apiKeysErr.value = e instanceof Error ? e.message : "Failed to delete API key";
} }
} }
@@ -1142,9 +1142,9 @@ async function deleteIdentityRow(id: number) {
v-if="row.active" v-if="row.active"
type="button" type="button"
class="rounded px-2 py-1 text-red-400 hover:bg-slate-800" class="rounded px-2 py-1 text-red-400 hover:bg-slate-800"
@click="revokeApiKey(row.id, row.label)" @click="deleteApiKey(row.id, row.label)"
> >
Revoke Delete
</button> </button>
</td> </td>
</tr> </tr>
+1 -1
View File
@@ -226,7 +226,7 @@ export const api = {
return handle(res); return handle(res);
}, },
async revokeApiKey(id: number): Promise<void> { async deleteApiKey(id: number): Promise<void> {
const res = await fetch(`/api/api-keys/${id}`, { const res = await fetch(`/api/api-keys/${id}`, {
method: "DELETE", method: "DELETE",
credentials: "include", credentials: "include",