<script>
    import { logOut} from '../apiServer';
    import { currentUser } from '../store';

    let user;

    currentUser.subscribe((value) => {
        user = value;
    });

    async function handleLogout(event) {
        event.preventDefault();
        const response = await logOut();
        if (200 <= response.status && response.status < 300) {
            currentUser.update(() => null);
        }
    }
</script>

<form on:submit={handleLogout}>
    @{user.username}
    <button
        class="border-slate-500 border-solid border-2 font-bold p-1 rounded"
        type="submit"
    >log out</button>
</form>

<style>
</style>
