From dce2bc75080ca0a3a706594e267b97058727956b Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 11 Jun 2022 23:17:20 -0500 Subject: [PATCH] Added account info panel with sign out button (#219) --- .../components/shared/navigation-bar.svelte | 62 ++++++++++++++++++- web/src/routes/__layout.svelte | 1 - web/src/routes/auth/logout.ts | 12 ++++ 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 web/src/routes/auth/logout.ts diff --git a/web/src/lib/components/shared/navigation-bar.svelte b/web/src/lib/components/shared/navigation-bar.svelte index 22f9c518c9..a9fcebf6f7 100644 --- a/web/src/lib/components/shared/navigation-bar.svelte +++ b/web/src/lib/components/shared/navigation-bar.svelte @@ -4,13 +4,15 @@ import type { ImmichUser } from '$lib/models/immich-user'; import { onMount } from 'svelte'; import { fade } from 'svelte/transition'; + import { postRequest } from '../../api'; import { serverEndpoint } from '../../constants'; + import { clickOutside } from './click-outside'; export let user: ImmichUser; let shouldShowAccountInfo = false; let shouldShowProfileImage = false; - + let shouldShowAccountInfoPanel = false; onMount(async () => { const res = await fetch(`${serverEndpoint}/user/profile-image/${user.id}`, { method: 'GET' }); @@ -24,6 +26,18 @@ const navigateToAdmin = () => { goto('/admin'); }; + + const showAccountInfoPanel = () => { + shouldShowAccountInfoPanel = true; + }; + + const logOut = async () => { + const res = await fetch('auth/logout', { method: 'POST' }); + + if (res.status == 200 && res.statusText == 'OK') { + goto('/auth/login'); + } + };
@@ -35,6 +49,7 @@
+
@@ -51,6 +66,7 @@ on:mouseover={() => (shouldShowAccountInfo = true)} on:focus={() => (shouldShowAccountInfo = true)} on:mouseleave={() => (shouldShowAccountInfo = false)} + on:click={showAccountInfoPanel} >
+ + {#if shouldShowAccountInfoPanel} +
(shouldShowAccountInfoPanel = false)} + > +
+ +
+ +

+ {user.firstName} + {user.lastName} +

+ +

{user.email}

+ +
+
+
+ +
+ +
+
+ {/if}
diff --git a/web/src/routes/__layout.svelte b/web/src/routes/__layout.svelte index 6245af9503..5468e49856 100644 --- a/web/src/routes/__layout.svelte +++ b/web/src/routes/__layout.svelte @@ -7,7 +7,6 @@ if (browser) { const { shouldShowAnnouncement, localVersion, remoteVersion } = await checkAppVersion(); - console.log('Recheck'); return { props: { url, shouldShowAnnouncement, localVersion, remoteVersion } }; } else { return { diff --git a/web/src/routes/auth/logout.ts b/web/src/routes/auth/logout.ts new file mode 100644 index 0000000000..59e0229dc6 --- /dev/null +++ b/web/src/routes/auth/logout.ts @@ -0,0 +1,12 @@ +import type { RequestHandler } from '@sveltejs/kit'; + +export const post: RequestHandler = async ({ request }) => { + return { + headers: { + 'Set-Cookie': 'session=deleted; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT', + }, + body: { + ok: true, + }, + }; +};