feat: initial logins

This commit is contained in:
2025-06-12 13:58:59 +01:00
parent b516196d38
commit 3bdee89eed
12 changed files with 716 additions and 444 deletions

View File

@@ -0,0 +1,14 @@
<script lang="ts">
import Navbar from "$lib/components/Navbar.svelte";
import crossUrl from "$lib/assets/cross.svg";
const { children } = $props();
</script>
<Navbar>
<a href="/">
<img src={crossUrl} alt="close" />
</a>
</Navbar>
{@render children?.()}

View 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, "/");
}
}
};

View File

@@ -0,0 +1,36 @@
<script lang="ts">
import Button from "$lib/components/Button.svelte";
import Text from "$lib/components/inputs/Text.svelte";
</script>
<form method="POST" action="?/login">
<label for="email">Email</label>
<Text type="email" name="email" placeholder="your@email.com" />
<label for="password">Password</label>
<Text type="password" name="password" placeholder="*********" />
<div class="actions">
<Button type="submit">Login</Button>
<Button formaction="?/signup">Signup</Button>
</div>
</form>
<style>
form {
display: flex;
flex-direction: column;
gap: 0.5rem;
max-width: 600px;
margin: 1rem auto;
}
label {
margin-top: 0.5rem;
}
.actions {
display: grid;
margin-top: 0.5rem;
grid-template-columns: 1fr 1fr;
gap: 1rem;
}
</style>