Files
drp-48/src/routes/auth/+page.server.ts
2025-06-12 15:42:29 +01:00

31 lines
1.1 KiB
TypeScript

import { redirect, error } from "@sveltejs/kit";
import type { Actions } from "./$types";
export const actions: Actions = {
signup: async ({ request, locals: { supabase } }) => {
const formData = await request.formData();
const email = formData.get("email") as string;
const password = formData.get("password") as string;
const { error: authError } = await supabase.auth.signUp({ email, password });
if (authError) {
error(400, "Failed to sign up: " + authError.message);
} else {
redirect(303, "/");
}
},
login: async ({ request, locals: { supabase } }) => {
const formData = await request.formData();
const email = formData.get("email") as string;
const password = formData.get("password") as string;
const { error: authError } = await supabase.auth.signInWithPassword({ email, password });
if (authError) {
error(400, "Failed to log in: " + authError.message);
} else {
redirect(303, "/");
}
}
};