From 6279afd2b29677cb39b7bdf7c1b0b72e98514d02 Mon Sep 17 00:00:00 2001 From: bender Date: Wed, 11 Mar 2026 20:12:17 +0000 Subject: [PATCH] Add src/app/login/page.tsx --- src/app/login/page.tsx | 206 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 src/app/login/page.tsx diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx new file mode 100644 index 0000000..2d533ae --- /dev/null +++ b/src/app/login/page.tsx @@ -0,0 +1,206 @@ +"use client"; + +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 { Mail, Lock } from 'lucide-react'; + +export default function LoginPage() { + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [error, setError] = useState(""); + const [loading, setLoading] = useState(false); + + const handleLogin = async (e: React.FormEvent) => { + e.preventDefault(); + setError(""); + setLoading(true); + + try { + // 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 pelo menos 6 caracteres."); + setLoading(false); + return; + } + + // Call login API + const response = await fetch("/api/auth/login", { + method: "POST", headers: { + "Content-Type": "application/json"}, + body: JSON.stringify({ email, password }), + }); + + const data = await response.json(); + + if (!response.ok) { + setError(data.message || "Erro ao fazer login. Tente novamente."); + setLoading(false); + return; + } + + // 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); + } + }; + + return ( + + + +
+
+
+

Bem-vindo de Volta

+

Faça login em sua conta FitFlow Pro

+ + {error && ( +
+ {error} +
+ )} + +
+
+ +
+ + setEmail(e.target.value)} + placeholder="seu.email@exemplo.com" + className="w-full pl-10 pr-4 py-2 rounded-lg border border-foreground/10 bg-background focus:outline-none focus:border-primary-cta/50 text-foreground placeholder-foreground/40 transition" + disabled={loading} + /> +
+
+ +
+ +
+ + setPassword(e.target.value)} + placeholder="••••••••" + className="w-full pl-10 pr-4 py-2 rounded-lg border border-foreground/10 bg-background focus:outline-none focus:border-primary-cta/50 text-foreground placeholder-foreground/40 transition" + disabled={loading} + /> +
+
+ + +
+ +
+

+ Não tem uma conta?{" "} + + Cadastre-se aqui + +

+
+ + +
+
+
+ + +
+ ); +}