page.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { redirect } from 'next/navigation';
  2. import { auth } from '@/auth';
  3. import { Button } from '@/components/ui/button';
  4. import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
  5. import { Input } from '@/components/ui/input';
  6. import { Label } from '@/components/ui/label';
  7. import { loginAction } from './actions';
  8. export default async function LoginPage({
  9. searchParams,
  10. }: {
  11. searchParams: Promise<{ error?: string }>;
  12. }) {
  13. const session = await auth();
  14. const params = await searchParams;
  15. if (session?.user?.id) {
  16. redirect('/');
  17. }
  18. return (
  19. <main className="grid min-h-screen place-items-center p-6">
  20. <Card className="w-full max-w-[420px]">
  21. <CardHeader>
  22. <p className="text-xs uppercase text-[hsl(var(--muted-foreground))]">EKB Auth</p>
  23. <CardTitle className="text-3xl">登录</CardTitle>
  24. </CardHeader>
  25. <CardContent>
  26. <form className="grid gap-4" action={loginAction}>
  27. <Label>
  28. 邮箱
  29. <Input name="email" type="email" defaultValue="admin@ekb.com" required />
  30. </Label>
  31. <Label>
  32. 密码
  33. <Input name="password" type="password" defaultValue="hashed_password_here" required />
  34. </Label>
  35. {params.error ? (
  36. <div className="rounded-md border border-red-300 bg-red-50 p-3 text-sm text-red-800">
  37. 邮箱或密码不正确
  38. </div>
  39. ) : null}
  40. <Button type="submit">登录</Button>
  41. </form>
  42. </CardContent>
  43. </Card>
  44. </main>
  45. );
  46. }