summaryrefslogtreecommitdiff
path: root/ui/lib
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-11 20:55:36 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-11 20:55:36 -0400
commit5ff106e910544788bc916626ae7665cb26e5af30 (patch)
treef03f98677293a9d892e2d21d1a9a80aeedab60a3 /ui/lib
parentd33c8af14c4adc1c15ab048299e06f9f35ae4de6 (diff)
Provide a separate "initial setup" endpoint that creates a user.
Diffstat (limited to 'ui/lib')
-rw-r--r--ui/lib/apiServer.js9
-rw-r--r--ui/lib/components/LogIn.svelte27
2 files changed, 15 insertions, 21 deletions
diff --git a/ui/lib/apiServer.js b/ui/lib/apiServer.js
index ccd6e66..46fcb53 100644
--- a/ui/lib/apiServer.js
+++ b/ui/lib/apiServer.js
@@ -3,12 +3,21 @@ import { channelsList, logins, messages } from '$lib/store';
export const apiServer = axios.create({
baseURL: '/api/',
+ validateStatus: (status) => status >= 200 && status < 500,
});
export async function boot() {
return apiServer.get('/boot');
}
+export async function setup(username, password) {
+ const data = {
+ name: username,
+ password,
+ };
+ return apiServer.post('/setup', data);
+}
+
export async function logIn(username, password) {
const data = {
name: username,
diff --git a/ui/lib/components/LogIn.svelte b/ui/lib/components/LogIn.svelte
index e1cda8a..bb80ccd 100644
--- a/ui/lib/components/LogIn.svelte
+++ b/ui/lib/components/LogIn.svelte
@@ -1,27 +1,12 @@
<script>
- import { goto } from '$app/navigation';
- import { logIn } from '$lib/apiServer';
- import { currentUser } from '$lib/store';
-
- let disabled = false;
- let username = '';
- let password = '';
-
- async function handleLogin() {
- disabled = true;
- const response = await logIn(username, password);
- if (200 <= response.status && response.status < 300) {
- currentUser.update(() => ({ username }));
- username = '';
- password = '';
- goto('/');
- }
- disabled = false;
- }
+ export let disabled = false;
+ export let username = '';
+ export let password = '';
+ export let legend = 'sign in';
</script>
<div class="card m-4 p-4">
- <form on:submit|preventDefault={handleLogin}>
+ <form on:submit|preventDefault>
<label class="label" for="username">
username
<input class="input" name="username" type="text" placeholder="username" bind:value={username} disabled={disabled}>
@@ -31,7 +16,7 @@
<input class="input" name="password" type="password" placeholder="password" bind:value={password} disabled={disabled}>
</label>
<button class="btn variant-filled" type="submit">
- sign in or up
+ {legend}
</button>
</form>
</div>