"use client"; import Link from "next/link"; import { FormEvent, useEffect, useState } from "react"; type AdminUser = { userId: string | null; email: string | null; createdAt: string | null; source: "env" | "database" }; async function loadUsers(): Promise { const response = await fetch("/api/admin/users", { cache: "no-store" }); const payload = await response.json().catch(() => null); if (!response.ok) throw new Error(payload?.error || "暂时无法读取管理员列表"); return payload.users; } export default function AdminUsersPage() { const [users, setUsers] = useState([]); const [email, setEmail] = useState(""); const [error, setError] = useState(""); useEffect(() => { void loadUsers().then(setUsers).catch((caught) => setError(caught.message)); }, []); async function add(event: FormEvent) { event.preventDefault(); setError(""); const response = await fetch("/api/admin/users", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ email }) }); const payload = await response.json().catch(() => null); if (!response.ok) { setError(payload?.error || "添加失败"); return; } setEmail(""); setUsers(await loadUsers()); } async function revoke(userId: string) { const response = await fetch("/api/admin/users", { method: "DELETE", headers: { "content-type": "application/json" }, body: JSON.stringify({ userId }) }); if (!response.ok) { const payload = await response.json().catch(() => null); setError(payload?.error || "撤销失败"); return; } setUsers(await loadUsers()); } return

管理员管理

兑换码管理

添加管理员

仅能添加已经注册的 Supabase 用户。

{error &&

{error}

}

当前管理员

{users.length} 位

{users.map((user) => )}
邮箱来源添加时间操作
{user.email || "—"}{user.source === "env" ? "环境配置" : "后台配置"}{user.createdAt ? new Date(user.createdAt).toLocaleString("zh-CN") : "—"}{user.userId && }
; }