cg / hackerproducts

63 files · 5,740 lines · 159.1 KB — Next.js 15, React 19, TypeScript, PostgreSQL, Object Storage, plain CSS.

Quick jump: page.tsx / page.tsx / globals.css / schema.sql / package.json

root / src / app / admin / page.tsx

src/app/admin/page.tsx · 68 lines · 1.7 KB← back to folder
1import type { Metadata } from "next";
2import Link from "next/link";
3import { redirect } from "next/navigation";
4import { getCurrentUser } from "@/lib/auth";
5import { listAllProductsForModeration } from "@/lib/products";
6import { ModerationRow } from "@/components/ModerationRow";
7
8export const dynamic = "force-dynamic";
9
10export const metadata: Metadata = {
11 title: "Moderation",
12 robots: { index: false, follow: false },
13};
14
15export default async function AdminPage() {
16 const user = await getCurrentUser();
17 if (!user) {
18 redirect("/login?next=/admin");
19 }
20
21 if (!user.is_admin) {
22 return (
23 <div>
24 <h1>Moderation</h1>
25 <p className="form-error">Admin access required.</p>
26 <p>
27 <Link href="/">← back to products</Link>
28 </p>
29 </div>
30 );
31 }
32
33 const products = await listAllProductsForModeration();
34
35 return (
36 <div>
37 <h1>Moderation</h1>
38 <p className="subtitle">Approve, hide, or remove submitted products.</p>
39
40 {products.length === 0 ? (
41 <p className="muted">No products submitted yet.</p>
42 ) : (
43 <table className="plain-table">
44 <thead>
45 <tr>
46 <th>Product</th>
47 <th>Maker</th>
48 <th>Status</th>
49 <th>Actions</th>
50 </tr>
51 </thead>
52 <tbody>
53 {products.map((product) => (
54 <ModerationRow
55 key={product.id}
56 slug={product.slug}
57 name={product.name}
58 ownerUsername={product.owner_username}
59 initialStatus={product.status}
60 />
61 ))}
62 </tbody>
63 </table>
64 )}
65 </div>
66 );
67}
68
cg / hackerproducts — hacker products