summaryrefslogtreecommitdiff
path: root/ui/lib/components/CurrentUser.svelte
blob: 56bf915ea672476383a4b0da683b113fb2089f09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<script>
  import { goto } from '$app/navigation';
  import { logOut } from '$lib/apiServer';
  import { currentUser } from '$lib/store';

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

<form onsubmit={handleLogout}>
  {#if $currentUser}
    <a href="/me">@{$currentUser.username}</a>
  {/if}
  <button class="border-slate-500 border-solid border-2 font-bold p-1 rounded" type="submit"
    >log out</button
  >
</form>

<style>
</style>