aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/login/+page.server.js
blob: 69077fc6c26df1b6dff465a6953dc717f4c5d496 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { invalid, redirect } from '@sveltejs/kit';
import { login } from '$lib/utils';

export const actions = {
	default: async ({ cookies, request }) => {
		let user = Object.fromEntries(await request.formData());
		try {
			await login(user, cookies);
		} catch (e) {
			return invalid(400, { error: 'Login failed' });
		}

		throw redirect(303, `/${user.username}/dashboard`);
	}
};