feat: working form
This commit is contained in:
+20
-11
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user