From 50ec0c9847dd1e9de7c2b8e850ff3f88888c8b43 Mon Sep 17 00:00:00 2001 From: g Date: Fri, 7 Feb 2025 06:03:55 +0000 Subject: [PATCH] update login page --- app/login/page.tsx | 98 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 app/login/page.tsx diff --git a/app/login/page.tsx b/app/login/page.tsx new file mode 100644 index 0000000..df12d5d --- /dev/null +++ b/app/login/page.tsx @@ -0,0 +1,98 @@ +"use client"; + +import { useState } from "react"; +import { useRouter } from "next/navigation"; +import Image from "next/image"; +import Link from "next/link"; +import { Button } from "@/components/ui/button"; +import { Checkbox } from "@/components/ui/checkbox"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Github } from "lucide-react"; // ✅ Added missing GitHub icon + +export default function LoginPage() { + const [username, setUsername] = useState(""); // ✅ Fixed incorrect state name + const [password, setPassword] = useState(""); + const [rememberMe, setRememberMe] = useState(false); // ✅ Fixed missing state + const [error, setError] = useState(""); + const router = useRouter(); + + async function handleLogin(e: React.FormEvent) { + e.preventDefault(); + setError(""); + + const res = await fetch("https://internal-api.inboxi.ng/api/auth/login", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ username, password }), + }); + + if (res.ok) { + const data = await res.json(); + console.log(data); + + document.cookie = `Authorization=${data.token}; path=/; Secure; SameSite=Strict; max-age=604800`; + + router.push("/dashboard"); + } else { + const data = await res.json(); + setError(data.error || "Invalid credentials"); + } + } + + return ( +
+
+
+

Welcome back

+

Please sign in to your account

+
+ + {error &&

{error}

} {/* ✅ Display login errors */} + +
+
+
+ {/* ✅ Changed Email to Username */} + setUsername(e.target.value)} + className="mt-1" + /> +
+
+ + setPassword(e.target.value)} + className="mt-1" + /> +
+
+ + + +
+ +

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

+
+
+ ); +} \ No newline at end of file