diff options
Diffstat (limited to 'hi-ui/src/lib/LogOut.svelte')
| -rw-r--r-- | hi-ui/src/lib/LogOut.svelte | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/hi-ui/src/lib/LogOut.svelte b/hi-ui/src/lib/LogOut.svelte new file mode 100644 index 0000000..738be24 --- /dev/null +++ b/hi-ui/src/lib/LogOut.svelte @@ -0,0 +1,28 @@ +<script> + import { logOut} from '../apiServer'; + import { currentUser } from '../store'; + + let user; + + currentUser.subscribe((value) => { + user = value; + }); + + async function handleLogout(event) { + const response = await logOut(); + if (200 <= response.status && response.status < 300) { + currentUser.update(() => null); + } + } +</script> + +<form on:submit|preventDefault={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> |
