From a64737165879bc5a2ad188ee997ce592bf290dd5 Mon Sep 17 00:00:00 2001 From: bender Date: Wed, 11 Mar 2026 20:10:39 +0000 Subject: [PATCH] Update src/app/login/page.tsx --- src/app/login/page.tsx | 196 ++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 121 deletions(-) diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 166c52e..2d533ae 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -3,56 +3,68 @@ import { useState } from "react"; import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider"; import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered'; +import ContactSplit from '@/components/sections/contact/ContactSplit'; import FooterBase from '@/components/sections/footer/FooterBase'; -import Input from '@/components/form/Input'; -import ButtonElasticEffect from '@/components/button/ButtonElasticEffect/ButtonElasticEffect'; -import { LogIn, Mail, Lock, Eye, EyeOff } from 'lucide-react'; +import { Mail, Lock } from 'lucide-react'; export default function LoginPage() { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); - const [showPassword, setShowPassword] = useState(false); - const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(""); - const [rememberMe, setRememberMe] = useState(false); + const [loading, setLoading] = useState(false); - const handleSubmit = async (e: React.FormEvent) => { + const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); setError(""); - setIsLoading(true); + setLoading(true); try { - // Simulate API call + // Validate inputs if (!email || !password) { setError("Por favor, preencha todos os campos."); + setLoading(false); return; } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { setError("Por favor, insira um email válido."); + setLoading(false); return; } if (password.length < 6) { - setError("A senha deve ter no mínimo 6 caracteres."); + setError("A senha deve ter pelo menos 6 caracteres."); + setLoading(false); return; } - // Simulate successful login - const response = { success: true, token: "user_token_123" }; + // Call login API + const response = await fetch("/api/auth/login", { + method: "POST", headers: { + "Content-Type": "application/json"}, + body: JSON.stringify({ email, password }), + }); - if (response.success) { - // Store session - sessionStorage.setItem("authToken", response.token); - sessionStorage.setItem("userEmail", email); - if (rememberMe) { - localStorage.setItem("userEmail", email); - } - // Redirect to dashboard - window.location.href = "/dashboard"; + const data = await response.json(); + + if (!response.ok) { + setError(data.message || "Erro ao fazer login. Tente novamente."); + setLoading(false); + return; } - } finally { - setIsLoading(false); + + // Store user session + localStorage.setItem("userSession", JSON.stringify({ + token: data.token, + user: data.user, + expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), + })); + + // Redirect to dashboard + window.location.href = "/dashboard"; + } catch (err) { + setError("Erro de conexão. Tente novamente mais tarde."); + setLoading(false); } }; @@ -78,140 +90,82 @@ export default function LoginPage() { { name: "Comunidade", id: "community" }, { name: "Perfil", id: "profile" } ]} - button={{ text: "Voltar ao Início", href: "/" }} + button={{ text: "Começar Agora", href: "contact" }} brandName="FitFlow Pro" /> -
+
-
- {/* Header */} -
-
-
- -
-
-

- Bem-vindo de Volta -

-

- Faça login na sua conta FitFlow Pro -

-
+
+

Bem-vindo de Volta

+

Faça login em sua conta FitFlow Pro

- {/* Error Message */} {error && ( -
+
{error}
)} - {/* Login Form */} -
- {/* Email Field */} -
-