From cc224f0091b6c85b1a036686a6ea52a6e1bcde4a Mon Sep 17 00:00:00 2001 From: EETagent Date: Sat, 3 Dec 2022 15:18:03 +0100 Subject: [PATCH] refactor: login in /auth, temporary logout --- frontend/src/lib/@api/index.ts | 2 +- .../(candidate)/(authenticated)/+layout.server.ts | 2 +- .../(candidate)/{ => auth}/login/+page.svelte | 2 +- .../login/[code=application]/+page.svelte | 0 .../routes/(candidate)/auth/logout/+page.server.ts | 13 +++++++++++++ 5 files changed, 16 insertions(+), 3 deletions(-) rename frontend/src/routes/(candidate)/{ => auth}/login/+page.svelte (96%) rename frontend/src/routes/(candidate)/{ => auth}/login/[code=application]/+page.svelte (100%) create mode 100644 frontend/src/routes/(candidate)/auth/logout/+page.server.ts diff --git a/frontend/src/lib/@api/index.ts b/frontend/src/lib/@api/index.ts index 6c4c32c..2b81ce6 100644 --- a/frontend/src/lib/@api/index.ts +++ b/frontend/src/lib/@api/index.ts @@ -1,7 +1,7 @@ import { goto } from "$app/navigation"; import type { AxiosError } from "axios"; -export const API_URL = "http://localhost:8000"; +export const API_URL = "http://localhost:9000"; export interface ApiError { error: AxiosError, diff --git a/frontend/src/routes/(candidate)/(authenticated)/+layout.server.ts b/frontend/src/routes/(candidate)/(authenticated)/+layout.server.ts index e0a95f7..b38a7f2 100644 --- a/frontend/src/routes/(candidate)/(authenticated)/+layout.server.ts +++ b/frontend/src/routes/(candidate)/(authenticated)/+layout.server.ts @@ -5,6 +5,6 @@ import { redirect } from '@sveltejs/kit'; export const load: LayoutServerLoad = ({ cookies }) => { const isAuthenticated = cookies.get('id'); if (!isAuthenticated) { - throw redirect(302, '/login'); + throw redirect(302, '/auth/login'); } }; diff --git a/frontend/src/routes/(candidate)/login/+page.svelte b/frontend/src/routes/(candidate)/auth/login/+page.svelte similarity index 96% rename from frontend/src/routes/(candidate)/login/+page.svelte rename to frontend/src/routes/(candidate)/auth/login/+page.svelte index 3b14bb4..449effb 100644 --- a/frontend/src/routes/(candidate)/login/+page.svelte +++ b/frontend/src/routes/(candidate)/auth/login/+page.svelte @@ -10,7 +10,7 @@ const redirectToCode = () => { // TODO: Validation if (applicationValue) { - goto(`/login/${applicationValue}`); + goto(`login/${applicationValue}`); } }; diff --git a/frontend/src/routes/(candidate)/login/[code=application]/+page.svelte b/frontend/src/routes/(candidate)/auth/login/[code=application]/+page.svelte similarity index 100% rename from frontend/src/routes/(candidate)/login/[code=application]/+page.svelte rename to frontend/src/routes/(candidate)/auth/login/[code=application]/+page.svelte diff --git a/frontend/src/routes/(candidate)/auth/logout/+page.server.ts b/frontend/src/routes/(candidate)/auth/logout/+page.server.ts new file mode 100644 index 0000000..e61626b --- /dev/null +++ b/frontend/src/routes/(candidate)/auth/logout/+page.server.ts @@ -0,0 +1,13 @@ +import type { PageServerLoad } from './$types'; + +import { redirect } from '@sveltejs/kit'; +import { logout } from '$lib/stores/candidate'; + +export const load: PageServerLoad = async ({ cookies }) => { + // TODO: Nefunguje?! + await logout(); + console.log(cookies); + cookies.delete('id', {path: '/'}); + cookies.delete('key', {path: '/'}); + throw redirect(302, '/auth/login'); +};