diff --git a/web/src/lib/api/api-keys.remote.ts b/web/src/lib/api/api-keys.remote.ts new file mode 100644 index 0000000..65be17e --- /dev/null +++ b/web/src/lib/api/api-keys.remote.ts @@ -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 + }); +}); diff --git a/web/src/lib/schema/api-keys.ts b/web/src/lib/schema/api-keys.ts new file mode 100644 index 0000000..aeca962 --- /dev/null +++ b/web/src/lib/schema/api-keys.ts @@ -0,0 +1,5 @@ +import { object, string, pipe, minLength } from 'valibot'; + +export const createKeySchema = object({ + name: pipe(string(), minLength(1)) +}); diff --git a/web/src/routes/dashboard/api-keys/+page.svelte b/web/src/routes/dashboard/api-keys/+page.svelte new file mode 100644 index 0000000..389577c --- /dev/null +++ b/web/src/routes/dashboard/api-keys/+page.svelte @@ -0,0 +1,114 @@ + + +
+ Copy this key now. It will not be shown again. +
+
+ {newKeyValue}
+
+
+ {key.name ?? 'Unnamed Key'}
+