From 8483926e19de632f3a4602fc04af056b0e863090 Mon Sep 17 00:00:00 2001 From: suricatingss Date: Mon, 8 Dec 2025 22:21:05 +0000 Subject: [PATCH] login fully functional --- app/pages/login.vue | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/app/pages/login.vue b/app/pages/login.vue index d5db484..c274a37 100644 --- a/app/pages/login.vue +++ b/app/pages/login.vue @@ -5,12 +5,6 @@ import type { FormSubmitEvent, AuthFormField } from '@nuxt/ui' const toast = useToast() -// create data model for the form -const credentials = reactive({ - email: '', - password: '', -}) - const providers = [{ label: 'Google', icon: 'i-simple-icons-google', @@ -44,40 +38,54 @@ const fields: AuthFormField[] = [{ type: 'checkbox' }] -type Schema = z.output +// actual login logic -function formSubmit(payload: FormSubmitEvent) { - console.log(payload); -} +const error_popup = ref(false) -async function sendLogin() { +async function sendLogin(u:string,p:string) { try { - await $fetch("/api/login", { + const r = await $fetch("/api/login", { method: "POST", - body: credentials + body: {"email": u, "password": p} }) - await refreshSession() await navigateTo('/dashboard') // user home page - } catch { - alert("Login failed.") + error_popup.value = true // show popup + } } + +const schema = z.object({ + email: z.email('Invalid email'), + password: z.string('Password is required').min(8, 'Must be at least 8 characters') +}) + + +function onSubmit(payload: FormSubmitEvent) { + const data = payload.data.email + console.log('Submitted', data) + sendLogin(payload.data.email, payload.data.password) } +