import { useState } from 'react'; import { useRouter } from 'next/router'; import Link from 'next/link'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import * as z from 'zod'; import { Loader2, Mail, Lock, ArrowRight, Sparkles } from 'lucide-react'; import { useAuth } from '@/hooks/useAuth'; import { Button } from '@/components/ui/button'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { Checkbox } from '@/components/ui/checkbox'; const formSchema = z.object({ email: z.string().email({ message: "请输入有效的邮箱地址" }), password: z.string().min(6, { message: "密码至少需要6个字符" }), }); export default function LoginPage() { const router = useRouter(); const { refreshUser } = useAuth(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { email: "", password: "", }, }); async function onSubmit(values: z.infer) { setIsLoading(true); setError(''); try { const res = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(values), }); const data = await res.json(); if (!res.ok) { throw new Error(data.message || '登录失败'); } // 登录成功,刷新用户状态并跳转 await refreshUser(); const redirect = router.query.redirect as string; router.push(redirect || '/'); } catch (err: any) { setError(err.message); } finally { setIsLoading(false); } } return (
{/* Left Panel - Visual & Branding */}
{/* Abstract Background */}
{/* Content */}
AOUN AI

释放您的
无限创意潜能

加入数万名创作者的行列,利用最先进的 AI 技术,将您的想法瞬间转化为现实。

© 2024 AOUN AI. All rights reserved.
{/* Right Panel - Login Form */}

欢迎回来

请输入您的账号信息以继续

( 邮箱地址
)} /> ( 密码
)} />
忘记密码?
{error && (
{error}
)}
还没有账号?
免费注册账号
); }