summaryrefslogtreecommitdiff
path: root/client/src/routes/login/+page.server.ts
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-07-17 23:42:55 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-07-17 23:44:11 +0200
commitbef3da2a567e3804e12355d9c3d5c09439dbe2ea (patch)
treeab7974c941bd31994da46150234976b33c2f61b5 /client/src/routes/login/+page.server.ts
parent145be2b3c92e254904d4040850e3c1e9b6a66f32 (diff)
Humble beginnings
Redirect to login if not logged in, on login session cookie is set and projects or reviews are listed.
Diffstat (limited to 'client/src/routes/login/+page.server.ts')
-rw-r--r--client/src/routes/login/+page.server.ts36
1 files changed, 36 insertions, 0 deletions
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;