From f4080f75b78d9664249506b678f0e7b9f827b6b1 Mon Sep 17 00:00:00 2001 From: EETagent Date: Thu, 12 Jan 2023 13:19:09 +0100 Subject: [PATCH 01/10] feat: add admin whoami --- frontend/src/lib/@api/admin.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/frontend/src/lib/@api/admin.ts b/frontend/src/lib/@api/admin.ts index 6c9d64c..7972315 100644 --- a/frontend/src/lib/@api/admin.ts +++ b/frontend/src/lib/@api/admin.ts @@ -8,6 +8,22 @@ import type { import axios from 'axios'; import { API_URL, errorHandler, type Fetch } from '.'; +export const apiWhoami = async (fetchSsr?: Fetch): Promise => { + const apiFetch = fetchSsr || fetch; + try { + const res = await apiFetch(API_URL + '/admin/whoami', { + method: 'GET', + credentials: 'include' + }); + if (res.status != 200) { + throw Error(await res.text()); + } + return await res.json(); + } catch (e) { + throw errorHandler(e, 'Failed to fetch whoami'); + } +}; + // Login as admin /admin/login export const apiLogin = async (data: AdminLogin): Promise => { try { From 87c35107ce01bfd380697ad8b93b10cbda359416 Mon Sep 17 00:00:00 2001 From: EETagent Date: Thu, 12 Jan 2023 13:19:17 +0100 Subject: [PATCH 02/10] feat: add auto logout --- .../admin/(authenticated)/+layout.server.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/+layout.server.ts b/frontend/src/routes/(admin)/admin/(authenticated)/+layout.server.ts index af8cb9a..55d325c 100644 --- a/frontend/src/routes/(admin)/admin/(authenticated)/+layout.server.ts +++ b/frontend/src/routes/(admin)/admin/(authenticated)/+layout.server.ts @@ -1,10 +1,19 @@ import type { LayoutServerLoad } from './$types'; import { redirect } from '@sveltejs/kit'; +import { apiWhoami } from '$lib/@api/admin'; -export const load: LayoutServerLoad = ({ cookies }) => { +export const load: LayoutServerLoad = async ({ cookies, fetch }) => { const isAuthenticated = cookies.get('id'); - if (!isAuthenticated) { - throw redirect(302, '/admin/auth/login'); + + if (isAuthenticated) { + const whoami = await apiWhoami(fetch).catch((e) => { + throw redirect(302, '/admin/auth/logout'); + }); + return { + whoami: whoami + }; + } else { + throw redirect(302, '/admin/auth/logout'); } }; From 61b49b77fc84deed943f8be606361f6d7b4b7993 Mon Sep 17 00:00:00 2001 From: EETagent Date: Thu, 12 Jan 2023 13:21:57 +0100 Subject: [PATCH 03/10] fix: put modal to screen center --- frontend/src/lib/components/Modal.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/lib/components/Modal.svelte b/frontend/src/lib/components/Modal.svelte index 4148a0c..3c56481 100644 --- a/frontend/src/lib/components/Modal.svelte +++ b/frontend/src/lib/components/Modal.svelte @@ -33,7 +33,7 @@ } .modal { - @apply absolute; + @apply fixed; @apply p-4; @apply rounded-xl; @apply transform: From 8e40aa46aff96f9391f911c8012b083c7f3176ee Mon Sep 17 00:00:00 2001 From: EETagent Date: Thu, 12 Jan 2023 13:25:39 +0100 Subject: [PATCH 04/10] feat: move header to right list only --- .../(admin)/admin/(authenticated)/dashboard/+page.svelte | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte index fcbaf01..cb1e381 100644 --- a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte +++ b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte @@ -98,11 +98,12 @@ {/if}
-
+
Background
+ {#each filters as filter}
@@ -194,7 +195,7 @@ .body { @apply h-full w-full; @apply float-left overflow-hidden; - @apply my-6 mx-12 ml-[27rem]; + @apply my-6 mt-14 mx-12 ml-[27rem]; } .body .controls { From ba7f38bee193d43711f2380e8eaeb93d3fc9dc43 Mon Sep 17 00:00:00 2001 From: EETagent Date: Thu, 12 Jan 2023 13:31:18 +0100 Subject: [PATCH 05/10] feat: move logout icon to component --- .../lib/components/dashboard/InfoButton.svelte | 15 ++------------- frontend/src/lib/components/icons/Logout.svelte | 13 +++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 frontend/src/lib/components/icons/Logout.svelte diff --git a/frontend/src/lib/components/dashboard/InfoButton.svelte b/frontend/src/lib/components/dashboard/InfoButton.svelte index 77d8533..ea58827 100644 --- a/frontend/src/lib/components/dashboard/InfoButton.svelte +++ b/frontend/src/lib/components/dashboard/InfoButton.svelte @@ -6,6 +6,7 @@ import Document from '../icons/Document.svelte'; import Download from '../icons/Download.svelte'; import { sticky } from 'tippy.js'; + import Logout from '../icons/Logout.svelte'; export let showDetails: boolean; @@ -50,19 +51,7 @@ delay: 0 }} > - + {:else} \ No newline at end of file From d295e202ed63d57d106092bfad517d59dd22aa60 Mon Sep 17 00:00:00 2001 From: EETagent Date: Thu, 12 Jan 2023 13:31:25 +0100 Subject: [PATCH 06/10] feat: add logout for admin --- .../admin/(authenticated)/dashboard/+page.svelte | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte index cb1e381..f68f497 100644 --- a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte +++ b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte @@ -9,6 +9,8 @@ import Table from '$lib/components/admin/table/Table.svelte'; import bacgkround from '$lib/assets/background.jpg'; + import Logout from '$lib/components/icons/Logout.svelte'; + import { goto } from '$app/navigation'; export let data: PageServerData; @@ -88,6 +90,10 @@ console.log(e); } }; + + const logout = async () => { + goto('/admin/auth/logout'); + }; {#if createCandidateModal} @@ -103,7 +109,6 @@
- {#each filters as filter}
@@ -112,7 +117,12 @@ {/each}
-

Uchazeči

+
+

Uchazeči

+ +
+
{/each}
From 4afd93323a8e302f56870b9b82afc3c8a7becb59 Mon Sep 17 00:00:00 2001 From: EETagent Date: Thu, 12 Jan 2023 13:47:54 +0100 Subject: [PATCH 10/10] fix: improve transitions --- .../(admin)/admin/(authenticated)/dashboard/+page.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte index d0f1388..9738767 100644 --- a/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte +++ b/frontend/src/routes/(admin)/admin/(authenticated)/dashboard/+page.svelte @@ -174,14 +174,14 @@ @apply flex items-center; @apply rounded-xl; - @apply transition-all duration-300; + @apply transition-all duration-200; @apply hover:bg-sspsBlue focus:bg-sspsBlue; @apply hover:text-white focus:text-white; } .list div :global(path) { - @apply transition-all duration-300; + @apply transition-all duration-100; } .list div:hover :global(path) {