feat: add API keys management page

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Sanju Sivalingam
2026-02-17 14:40:42 +05:30
parent ebe82c7481
commit 9422e94a8e
3 changed files with 146 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import { form, getRequestEvent, query } from '$app/server';
import { auth } from '$lib/server/auth';
import { createKeySchema } from '$lib/schema/api-keys';
export const listKeys = query(async () => {
const { request } = getRequestEvent();
return await auth.api.listApiKeys({ headers: request.headers });
});
export const createKey = form(createKeySchema, async ({ name }) => {
const { request } = getRequestEvent();
const result = await auth.api.createApiKey({
body: { name, prefix: 'dc' },
headers: request.headers
});
return result;
});
export const deleteKey = form(async () => {
const { request } = getRequestEvent();
const formData = await request.clone().formData();
const keyId = formData.get('keyId') as string;
await auth.api.deleteApiKey({
body: { keyId },
headers: request.headers
});
});

View File

@@ -0,0 +1,5 @@
import { object, string, pipe, minLength } from 'valibot';
export const createKeySchema = object({
name: pipe(string(), minLength(1))
});