<script>
    import { goto } from '$app/navigation';
    import { logIn } from '$lib/apiServer';

    import LogIn from '$lib/components/LogIn.svelte';

    let username = "", password = "";
    let pending = false;
    $: disabled = pending;

    async function onSubmit() {
        pending = true;
        const response = await logIn(username, password);
        if (200 <= response.status && response.status < 300) {
            username = '';
            password = '';
            goto('/');
        }
        pending = false;
    }
</script>

<LogIn bind:disabled bind:username bind:password on:submit={onSubmit} />
