arbitrage-engine/frontend/app/login/page.tsx

76 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useState } from "react";
import { useAuth } from "@/lib/auth";
import { useRouter } from "next/navigation";
import Link from "next/link";
export default function LoginPage() {
const { login } = useAuth();
const router = useRouter();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError("");
setLoading(true);
try {
await login(email, password);
router.push("/");
} catch (err: any) {
setError(err.message || "登录失败");
} finally {
setLoading(false);
}
};
return (
<div className="min-h-screen bg-slate-50 flex items-center justify-center p-4">
<div className="w-full max-w-md">
<div className="bg-white rounded-xl shadow-sm border border-slate-200 p-8">
<div className="text-center mb-8">
<h1 className="text-2xl font-bold text-slate-800"> Arbitrage Engine</h1>
<p className="text-slate-500 text-sm mt-2"></p>
</div>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label className="block text-sm font-medium text-slate-700 mb-1"></label>
<input
type="email" value={email} onChange={e => setEmail(e.target.value)}
className="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="you@example.com" required
/>
</div>
<div>
<label className="block text-sm font-medium text-slate-700 mb-1"></label>
<input
type="password" value={password} onChange={e => setPassword(e.target.value)}
className="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="••••••••" required
/>
</div>
{error && <p className="text-red-500 text-sm">{error}</p>}
<button
type="submit" disabled={loading}
className="w-full bg-blue-600 hover:bg-blue-700 text-white py-2.5 rounded-lg font-medium text-sm transition-colors disabled:opacity-50"
>
{loading ? "登录中..." : "登录"}
</button>
</form>
<p className="text-center text-sm text-slate-500 mt-6">
{" "}
<Link href="/register" className="text-blue-600 hover:underline"></Link>
</p>
</div>
</div>
</div>
);
}