feat(Login): aplicada funcionalidad al formulario de Login

parent 18bd20e6
Showing with 32 additions and 7 deletions
<script setup>
import Header from '@/components/Header.vue';
import SignLayout from '@/components/SignLayout.vue';
</script>
<template>
<Header></Header>
<SignLayout>
<div class="form-signin w-100 p-5 shadow rounded bg-white form-card">
<h2 class="mb-4 text-center">Iniciar Sesión</h2>
<form>
<form @submit.prevent="handleLogin">
<div class="form-floating mb-4">
<input
type="email"
class="form-control"
id="inputEmail"
placeholder="Correo electrónico"
v-model="email"
required
>
<label for="inputEmail">Correo electrónico</label>
......@@ -27,6 +22,7 @@ import SignLayout from '@/components/SignLayout.vue';
class="form-control"
id="inputPassword"
placeholder="Contraseña"
v-model="password"
required
>
<label for="inputPassword">Contraseña</label>
......@@ -36,6 +32,10 @@ import SignLayout from '@/components/SignLayout.vue';
Entrar
</button>
<div v-if="errorMsg" class="alert alert-danger" role="alert">
{{ errorMsg }}
</div>
<p class="text-center mt-4">
¿No tienes cuenta?
<a href="/auth/register" class="text-decoration-none">Regístrate aquí</a>
......@@ -45,6 +45,31 @@ import SignLayout from '@/components/SignLayout.vue';
</SignLayout>
</template>
<script setup>
import SignLayout from '@/components/SignLayout.vue';
import { useAuthStore } from '@/stores/authStore';
import { useRouter } from 'vue-router';
import { ref } from 'vue';
const authStore = useAuthStore();
const router = useRouter();
const email = ref('');
const password = ref('');
const errorMsg = ref('');
async function handleLogin() {
errorMsg.value = '';
try {
await authStore.login({ email: email.value, password: password.value }),
router.push('/recipes');
} catch (error) {
errorMsg.value = error.message;
}
}
</script>
<style scope>
.form-card .btn-style {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment