34 lines
749 B
JavaScript
34 lines
749 B
JavaScript
import { createUser } from '$lib/server/db/user';
|
|
import { redirect } from '@sveltejs/kit';
|
|
|
|
/** @type {import('@sveltejs/kit').ServerLoad} */
|
|
export async function load({ cookies }) {
|
|
if (cookies.get('token')) {
|
|
redirect(302, '/');
|
|
}
|
|
}
|
|
|
|
/** @type {import('@sveltejs/kit').Action} */
|
|
async function POST({ request }) {
|
|
if (request.method !== 'POST') {
|
|
return;
|
|
}
|
|
|
|
const data = await request.formData();
|
|
const username = data.get('username')?.toString();
|
|
const password = data.get('password')?.toString();
|
|
|
|
if (!username || !password) {
|
|
return;
|
|
}
|
|
|
|
const result = await createUser(username, password);
|
|
|
|
console.log(result);
|
|
}
|
|
|
|
/** @type {import('@sveltejs/kit').Actions} */
|
|
export const actions = {
|
|
default: POST
|
|
};
|