diff options
Diffstat (limited to 'ui/lib')
| -rw-r--r-- | ui/lib/apiServer.js | 9 | ||||
| -rw-r--r-- | ui/lib/components/LogIn.svelte | 27 |
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> |
