From 5ff106e910544788bc916626ae7665cb26e5af30 Mon Sep 17 00:00:00 2001
From: Owen Jacobson <owen@grimoire.ca>
Date: Fri, 11 Oct 2024 20:55:36 -0400
Subject: Provide a separate "initial setup" endpoint that creates a user.

---
 ui/routes/(login)/setup/+page.svelte | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 ui/routes/(login)/setup/+page.svelte

(limited to 'ui/routes/(login)/setup/+page.svelte')

diff --git a/ui/routes/(login)/setup/+page.svelte b/ui/routes/(login)/setup/+page.svelte
new file mode 100644
index 0000000..252e79b
--- /dev/null
+++ b/ui/routes/(login)/setup/+page.svelte
@@ -0,0 +1,25 @@
+<script>
+    import { goto } from '$app/navigation';
+    import { setup } from '$lib/apiServer';
+    import { currentUser } from '$lib/store';
+
+    import LogIn from '$lib/components/LogIn.svelte';
+
+    let disabled;
+    let username;
+    let password;
+
+    async function onSubmit() {
+        disabled = true;
+        const response = await setup(username, password);
+        if (200 <= response.status && response.status < 300) {
+            currentUser.update(() => ({ username }));
+            username = '';
+            password = '';
+            goto('/');
+        }
+        disabled = false;
+    }
+</script>
+
+<LogIn bind:disabled bind:username bind:password legend="set up" on:submit={onSubmit} />
-- 
cgit v1.2.3

