<script>
  import { goto } from '$app/navigation';
  import { logOut } from '$lib/apiServer.js';
  import { currentUser } from '$lib/store';

  async function onsubmit(event) {
    event.preventDefault();
    const response = await logOut();
    if (200 <= response.status && response.status < 300) {
      currentUser.set(null);
      await goto('/login');
    }
  }
</script>

<form class="form" {onsubmit}>
  <button type="submit">log out</button>
</form>
