From bef3da2a567e3804e12355d9c3d5c09439dbe2ea Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Thu, 17 Jul 2025 23:42:55 +0200 Subject: Humble beginnings Redirect to login if not logged in, on login session cookie is set and projects or reviews are listed. --- client/src/routes/login/+page.server.ts | 36 +++++++++++++++++++++++++++++++++ client/src/routes/login/+page.svelte | 22 ++++++++++++++++++++ client/src/routes/login/+page.ts | 7 +++++++ 3 files changed, 65 insertions(+) create mode 100644 client/src/routes/login/+page.server.ts create mode 100644 client/src/routes/login/+page.svelte create mode 100644 client/src/routes/login/+page.ts (limited to 'client/src/routes/login') diff --git a/client/src/routes/login/+page.server.ts b/client/src/routes/login/+page.server.ts new file mode 100644 index 0000000..738b8ad --- /dev/null +++ b/client/src/routes/login/+page.server.ts @@ -0,0 +1,36 @@ +import { redirect } from '@sveltejs/kit'; +import { base } from '$app/paths'; +import type { Actions } from './$types'; +import { client } from '$lib/fetch-client'; + +export const actions = { + default: async ({ request, fetch }) => { + const data = await request.formData(); + const username = data.get('username'); + const password = data.get('password'); + const ret = data.get('return'); + + const login = await client.POST('/login', { + body: { + username: username?.toString() || '', + password: password?.toString() || '' + }, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + fetch + }); + if (login.data?.ok === true) { + if (ret) { + redirect(303, ret.toString()); + } else { + redirect(303, base); + } + } else { + return { + error: true, + username: username + }; + } + } +} satisfies Actions; diff --git a/client/src/routes/login/+page.svelte b/client/src/routes/login/+page.svelte new file mode 100644 index 0000000..8a91125 --- /dev/null +++ b/client/src/routes/login/+page.svelte @@ -0,0 +1,22 @@ + + +{#if form?.error} +

Unknown username or password

+{/if} + +
+ + + + +
diff --git a/client/src/routes/login/+page.ts b/client/src/routes/login/+page.ts new file mode 100644 index 0000000..70d306a --- /dev/null +++ b/client/src/routes/login/+page.ts @@ -0,0 +1,7 @@ +import type { PageLoad } from './$types'; + +export const load: PageLoad = async ({ url }) => { + return { + return: url.searchParams.get('return') || '' + }; +}; -- cgit v1.2.3-70-g09d2