All files / components/LogoutLink LogoutLink.svelte

100% Statements 26/26
100% Branches 0/0
100% Functions 0/0
100% Lines 26/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 271x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
<script lang="ts">
  import { page } from "$app/stores";
  import logout from "$lib/actions/logout";
  import { createEventDispatcher, type ComponentProps } from "svelte";
  import Link from "$lib/components/Link";
  import { getCurrentUserStore } from "$lib/context/currentUser";
 
  const currentUser = getCurrentUserStore();
 
  const dispatch = createEventDispatcher();
 
  type $$Props = Omit<ComponentProps<Link>, "href">;
 
  $: encodedState = encodeURIComponent($page.url.pathname + $page.url.search + $page.url.hash);
  $: logoutLinkLocation = `/logout?state=${encodedState}`;
</script>
 
<Link
  href={logoutLinkLocation}
  on:click={(e) => {
    e.preventDefault(); // we can't use on:click|preventDefault with custom elements
    if (!dispatch("click", e, { cancelable: true }) || !logout) return;
    logout({ currentUser, fetch });
  }}
  {...$$props}><slot>Logout</slot></Link
>