Fix admin-login route - create proper page at /admin-login
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
6543d888c8
commit
8867e66928
2 changed files with 1 additions and 92 deletions
|
|
@ -10,7 +10,6 @@ export default function AdminLoginPage() {
|
|||
const [error, setError] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
// Check if already logged in
|
||||
useEffect(() => {
|
||||
const token = localStorage.getItem("admin_token");
|
||||
if (token) {
|
||||
|
|
@ -76,9 +75,7 @@ export default function AdminLoginPage() {
|
|||
/>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p className="text-red-400 text-sm">{error}</p>
|
||||
)}
|
||||
{error && <p className="text-red-400 text-sm">{error}</p>}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function AdminLogin() {
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const router = useRouter();
|
||||
|
||||
const handleLogin = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
setError("");
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/admin/auth", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
// Store admin session
|
||||
localStorage.setItem("admin_token", data.token);
|
||||
localStorage.setItem("admin_user", JSON.stringify(data.admin));
|
||||
router.push("/admin");
|
||||
} else {
|
||||
setError(data.error || "Login failed");
|
||||
}
|
||||
} catch (err) {
|
||||
setError("Login failed");
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gray-900">
|
||||
<div className="w-full max-w-md p-8 bg-gray-800 rounded-2xl">
|
||||
<h1 className="text-2xl font-bold text-white text-center mb-2">Tia Admin</h1>
|
||||
<p className="text-gray-400 text-center mb-8">Platform Management</p>
|
||||
|
||||
{error && (
|
||||
<div className="mb-4 p-3 bg-red-500/20 text-red-400 rounded-lg text-sm">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleLogin} className="space-y-4">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
className="w-full p-4 bg-gray-700 border border-gray-600 rounded-xl text-white placeholder-gray-400"
|
||||
required
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
className="w-full p-4 bg-gray-700 border border-gray-600 rounded-xl text-white placeholder-gray-400"
|
||||
required
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="w-full p-4 bg-rose-500 text-white rounded-xl font-medium disabled:opacity-50"
|
||||
>
|
||||
{loading ? "Logging in..." : "Login"}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div className="mt-6 text-center">
|
||||
<a href="/login" className="text-gray-400 text-sm hover:text-white">
|
||||
← Back to Family Login
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue