From f7b97635bdd2fe9bafd55e90d4f56cefc5948e1c Mon Sep 17 00:00:00 2001 From: bender Date: Mon, 9 Mar 2026 19:57:28 +0000 Subject: [PATCH] Switch to version 2: added src/app/login/page.tsx --- src/app/login/page.tsx | 158 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 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..9e7d496 --- /dev/null +++ b/src/app/login/page.tsx @@ -0,0 +1,158 @@ +"use client"; + +import { useState } from "react"; +import { useRouter } from "next/navigation"; +import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider"; +import NavbarLayoutFloatingInline from "@/components/navbar/NavbarLayoutFloatingInline"; +import Link from "next/link"; +import { Heart } from "lucide-react"; + +export default function LoginPage() { + const router = useRouter(); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + const [error, setError] = useState(""); + const [isLoading, setIsLoading] = useState(false); + + const navItems = [ + { name: "Home", id: "/" }, + { name: "Browse Animals", id: "/animals" }, + { name: "About", id: "/about" }, + { name: "Login", id: "/login" }, + ]; + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setError(""); + setIsLoading(true); + + try { + const response = await fetch("/api/auth/login", { + method: "POST", headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ email, password }), + }); + + if (!response.ok) { + const data = await response.json(); + setError(data.message || "Login failed. Please try again."); + setIsLoading(false); + return; + } + + const data = await response.json(); + localStorage.setItem("authToken", data.token); + localStorage.setItem("user", JSON.stringify(data.user)); + router.push("/dashboard"); + } catch (err) { + setError("An error occurred. Please try again."); + setIsLoading(false); + } + }; + + return ( + + + +
+
+
+
+ +
+

+ Welcome Back +

+

+ Log in to your PawsHome account +

+ + {error && ( +
+ {error} +
+ )} + +
+
+ + setEmail(e.target.value)} + placeholder="you@example.com" + required + className="w-full px-4 py-2 border border-accent rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-cta bg-background text-foreground placeholder-foreground/50" + /> +
+ +
+ + setPassword(e.target.value)} + placeholder="••••••••" + required + className="w-full px-4 py-2 border border-accent rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-cta bg-background text-foreground placeholder-foreground/50" + /> +
+ + +
+ +
+

+ Don't have an account?{" "} + + Sign up + +

+
+ +
+ + Forgot your password? + +
+
+
+
+
+ ); +}