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;