feat: working form

This commit is contained in:
2026-09-15 00:40:54 +02:00
parent f6ba8f46d6
commit 2f9cfd3f1a
5 changed files with 110 additions and 54 deletions
+20 -11
View File
@@ -1,23 +1,32 @@
---
import Layout from "../layouts/layout.astro";
import LoginForm from "../islands/LoginForm.vue";
import LoginForm from '../islands/LoginForm.vue'
import Layout from '../layouts/layout.astro'
import { loginSchema } from '../schemas/login'
let email = "";
let error = "";
let email = ''
let error = ''
if (Astro.request.method === "POST") {
const formData = await Astro.request.formData();
if (Astro.request.method === 'POST') {
const formData = await Astro.request.formData()
const input = {
email: formData.get('email'),
password: formData.get('password'),
}
const result = loginSchema.safeParse(input)
email = formData.get("email")?.toString() ?? "";
email = typeof input.email === 'string' ? input.email : ''
if (!email) {
error = "E-Mail shouldn't be empty.";
if (!result.success) {
error = result.error.issues[0]?.message ?? 'Invalid form data.'
} else {
email = result.data.email
console.log('POST DATA', result.data)
}
}
---
<Layout>
<h1 class="text-2xl font-bold">Sign in</h1>
<h1 class='text-2xl font-bold'>Sign in</h1>
<LoginForm client:load email={email} />
<LoginForm client:load email={email} error={error} />
</Layout>