● Zion Boggan
repos/Stepping App/apps/web/src/app/admin/login/page.tsx
zionboggan.com ↗
62 lines · tsx
History for this file →
1
import { redirect } from "next/navigation";
2
import { login, getCurrentUser, isAdmin } from "@/lib/auth";
3
 
4
export const dynamic = "force-dynamic";
5
 
6
export const metadata = { title: "Admin · Stepping", robots: { index: false } };
7
 
8
export default async function AdminLogin({
9
  searchParams,
10
}: {
11
  searchParams: Promise<{ error?: string }>;
12
}) {
13
  const { error } = await searchParams;
14
  if (isAdmin(await getCurrentUser())) redirect("/admin");
15
 
16
  async function doLogin(formData: FormData) {
17
    "use server";
18
    const email = String(formData.get("email") ?? "");
19
    const password = String(formData.get("password") ?? "");
20
    const ok = await login(email, password);
21
    redirect(ok ? "/admin" : "/admin/login?error=1");
22
  }
23
 
24
  return (
25
    <main className="mx-auto flex min-h-[100svh] w-full max-w-md flex-col justify-center px-6">
26
      <p className="kicker text-ash">Stepping</p>
27
      <h1 className="display mt-2 text-5xl">Admin</h1>
28
      <p className="serif mt-3 text-lg text-ash">Sign in to manage the platform.</p>
29
 
30
      {error ? (
31
        <p className="kicker mt-6 border border-gold px-4 py-3 text-gold">
32
          Wrong email or password.
33
        </p>
34
      ) : null}
35
 
36
      <form action={doLogin} className="mt-8 flex flex-col gap-4">
37
        <input
38
          name="email"
39
          type="email"
40
          required
41
          autoComplete="username"
42
          placeholder="Email"
43
          className="serif border-b border-[var(--line)] bg-transparent py-3 text-xl text-bone outline-none placeholder:text-ash focus:border-gold"
44
        />
45
        <input
46
          name="password"
47
          type="password"
48
          required
49
          autoComplete="current-password"
50
          placeholder="Password"
51
          className="serif border-b border-[var(--line)] bg-transparent py-3 text-xl text-bone outline-none placeholder:text-ash focus:border-gold"
52
        />
53
        <button
54
          type="submit"
55
          className="kicker mt-4 bg-gold px-6 py-4 text-stage hover:bg-gold-bright"
56
        >
57
          Sign in
58
        </button>
59
      </form>
60
    </main>
61
  );
62
}