feat: initial logins
This commit is contained in:
30
src/routes/auth/+page.server.ts
Normal file
30
src/routes/auth/+page.server.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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, "/");
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user