feat(admin): add user account management

This commit is contained in:
dmg
2026-08-01 14:16:46 -04:00
parent c5de0a1810
commit 10554eeaff
10 changed files with 690 additions and 6 deletions
+17
View File
@@ -5,6 +5,23 @@ import { db } from "@/lib/database";
const UI_ACCESSED = "games.minecraft.account-manager.ui.accessed";
export async function recordAdminEvent(
admin: { email: string | null; name: string | null },
targetUserId: string,
type: string,
data: Record<string, unknown>,
) {
const requestHeaders = await headers();
const ipAddress = getClientIp(requestHeaders, process.env.TRUST_PROXY === "true");
return recordEvent(db, {
type,
source: "/web/admin",
subject: `user/${targetUserId}`,
ipAddress: ipAddress ?? undefined,
data: { ...data, adminEmail: admin.email, adminName: admin.name },
});
}
export async function recordUserEvent(
user: { id: string },
type: string,
+14
View File
@@ -0,0 +1,14 @@
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";
import { adminAuthOptions, requiredAdminRole } from "./admin-auth";
export async function requireAdminSession() {
const session = await getServerSession(adminAuthOptions);
const roles = (session?.user as { roles?: string[] } | undefined)?.roles ?? [];
if (!session || !roles.includes(requiredAdminRole)) redirect("/admin/login");
return {
email: session.user?.email ?? null,
name: session.user?.name ?? null,
};
}