From 66d3fcf2e22f057bacce8d97d43a13c1c5a9ad09 Mon Sep 17 00:00:00 2001
From: Owen Jacobson <owen@grimoire.ca>
Date: Tue, 29 Oct 2024 23:29:22 -0400
Subject: Add `change password` UI + API.

The protocol here re-checks the caller's password, as a "I left myself logged in" anti-pranking check.
---
 ui/lib/components/CurrentUser.svelte | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 ui/lib/components/CurrentUser.svelte

(limited to 'ui/lib/components/CurrentUser.svelte')

diff --git a/ui/lib/components/CurrentUser.svelte b/ui/lib/components/CurrentUser.svelte
new file mode 100644
index 0000000..4b1b974
--- /dev/null
+++ b/ui/lib/components/CurrentUser.svelte
@@ -0,0 +1,26 @@
+<script>
+    import { goto } from '$app/navigation';
+    import { logOut} from '$lib/apiServer';
+    import { currentUser } from '$lib/store';
+
+    async function handleLogout() {
+        const response = await logOut();
+        if (200 <= response.status && response.status < 300) {
+            currentUser.update(() => null);
+            goto('/login');
+        }
+    }
+</script>
+
+<form on:submit|preventDefault={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>
-- 
cgit v1.2.3

