diff --git a/apps/web/app/admin/users/[id]/page.tsx b/apps/web/app/admin/users/[id]/page.tsx
new file mode 100644
index 0000000..3427483
--- /dev/null
+++ b/apps/web/app/admin/users/[id]/page.tsx
@@ -0,0 +1,364 @@
+import Link from "next/link";
+import { notFound } from "next/navigation";
+
+import { Panel, PanelCard } from "@/components/panel";
+import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
+import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
+import { prisma } from "@/lib/db";
+import { requireAdmin } from "@/lib/session";
+
+import {
+ PageBody,
+ PageHeader,
+} from "../../../dashboard/components/page-header";
+import { RevokeSessionButton, UserAdminActions } from "./user-admin-client";
+
+const Row = ({
+ label,
+ children,
+}: {
+ label: string;
+ children: React.ReactNode;
+}) => (
+
+ {label}
+ {children}
+
+);
+
+const Empty = ({ children }: { children: React.ReactNode }) => (
+
+ {children}
+
+);
+
+const formatDate = (date: Date | null | undefined) =>
+ date ? date.toLocaleString() : "-";
+
+const formatSignInMethods = (providers: string[], passkeys: number) =>
+ [...providers, ...(passkeys > 0 ? [`${passkeys} passkey(s)`] : [])].join(
+ ", "
+ ) || "-";
+
+const UserBadges = ({
+ banned,
+ role,
+ superAdmin,
+}: {
+ banned: boolean | null;
+ role: string | null;
+ superAdmin: boolean;
+}) => (
+ <>
+ {superAdmin ? (
+
+ Super Admin
+
+ ) : (
+ {role === "admin" ? "Admin" : "User"}
+ )}
+ {banned && (
+
+ Banned
+
+ )}
+ >
+);
+
+const AdminManageUserPage = async ({
+ params,
+}: {
+ params: Promise<{ id: string }>;
+}) => {
+ const viewer = await requireAdmin();
+ const viewerSuperAdmin =
+ (viewer as { superAdmin?: boolean }).superAdmin ?? false;
+ const { id } = await params;
+
+ const now = new Date();
+ const [user, auditLogs] = await Promise.all([
+ prisma.user.findUnique({
+ include: {
+ _count: { select: { passkeys: true, serverMemberships: true } },
+ accounts: {
+ orderBy: { createdAt: "asc" },
+ select: { createdAt: true, id: true, providerId: true },
+ },
+ servers: {
+ orderBy: { createdAt: "desc" },
+ select: {
+ id: true,
+ memory: true,
+ name: true,
+ node: { select: { name: true } },
+ nodeId: true,
+ status: true,
+ },
+ where: { deletedAt: null },
+ },
+ sessions: {
+ orderBy: { updatedAt: "desc" },
+ select: {
+ createdAt: true,
+ expiresAt: true,
+ id: true,
+ impersonatedBy: true,
+ ipAddress: true,
+ updatedAt: true,
+ userAgent: true,
+ },
+ where: { expiresAt: { gt: now } },
+ },
+ subscriptions: {
+ orderBy: { createdAt: "desc" },
+ select: {
+ currency: true,
+ currentPeriodEnd: true,
+ id: true,
+ plan: { select: { name: true } },
+ priceMonthCents: true,
+ provider: true,
+ status: true,
+ },
+ },
+ },
+ where: { id },
+ }),
+ prisma.auditLog.findMany({
+ orderBy: { createdAt: "desc" },
+ select: {
+ action: true,
+ actorEmail: true,
+ createdAt: true,
+ id: true,
+ ipAddress: true,
+ },
+ take: 15,
+ where: { OR: [{ actorId: id }, { targetId: id, targetType: "user" }] },
+ }),
+ ]);
+ if (!user) {
+ notFound();
+ }
+
+ const isSelf = (viewer as { id?: string }).id === user.id;
+ const displayName = user.name || user.email;
+
+ return (
+ <>
+
+ Back to users
+
+ }
+ meta={
+
+ }
+ title={displayName}
+ />
+
+
+
+
+
+ {user.image && (
+
+ )}
+
+ {displayName.charAt(0).toUpperCase()}
+
+
+
+
+ {user.email}{" "}
+
+ ({user.emailVerified ? "verified" : "unverified"})
+
+
+
+ {user.id}
+
+ {formatDate(user.createdAt)}
+ {formatDate(user.updatedAt)}
+
+ {formatSignInMethods(
+ user.accounts.map((a) => a.providerId),
+ user._count.passkeys
+ )}
+
+
+ {user._count.serverMemberships}
+
+ {user.banned && (
+ <>
+ {user.banReason ?? "-"}
+
+ {user.banExpires ? formatDate(user.banExpires) : "Never"}
+
+ >
+ )}
+
+
+
+
+
s.id)}
+ superAdmin={user.superAdmin}
+ userId={user.id}
+ viewerSuperAdmin={viewerSuperAdmin}
+ />
+
+
+
+ {user.servers.length === 0 ? (
+ This user owns no servers.
+ ) : (
+ user.servers.map((server) => (
+
+ {server.name}
+
+
+ {server.node?.name ?? "-"}
+
+ {server.memory} MiB
+
+ {server.status?.replaceAll("_", " ") ??
+ (server.nodeId ? "installed" : "not deployed")}
+
+
+
+ ))
+ )}
+
+
+
+ {user.subscriptions.length > 0 && (
+
+
+ {user.subscriptions.map((sub) => (
+
+
+ {sub.plan?.name ?? "Custom"}{" "}
+
+ via {sub.provider}
+
+
+
+
+ {(sub.priceMonthCents / 100).toFixed(2)}{" "}
+ {sub.currency.toUpperCase()}/mo
+
+
+ Renews {formatDate(sub.currentPeriodEnd)}
+
+ {sub.status}
+
+
+ ))}
+
+
+ )}
+
+
+
+ {user.sessions.length === 0 ? (
+ No active sessions.
+ ) : (
+ user.sessions.map((session) => (
+
+
+
+ {session.ipAddress ?? "Unknown IP"}
+ {session.impersonatedBy && (
+
+ Impersonation
+
+ )}
+
+
+ {session.userAgent ?? "Unknown device"}
+
+
+
+
+ Last active {formatDate(session.updatedAt)}
+
+ {viewerSuperAdmin && (
+
+ )}
+
+
+ ))
+ )}
+
+
+
+
+ View audit log
+
+ }
+ title="Recent activity"
+ >
+
+ {auditLogs.length === 0 ? (
+ No activity recorded.
+ ) : (
+ auditLogs.map((log) => (
+
+
+ {log.action}
+
+ by {log.actorEmail ?? "system"}
+ {log.ipAddress && ` · ${log.ipAddress}`}
+
+
+
+ {formatDate(log.createdAt)}
+
+
+ ))
+ )}
+
+
+
+
+ >
+ );
+};
+
+export default AdminManageUserPage;
diff --git a/apps/web/app/admin/users/[id]/user-admin-client.tsx b/apps/web/app/admin/users/[id]/user-admin-client.tsx
new file mode 100644
index 0000000..20b49dd
--- /dev/null
+++ b/apps/web/app/admin/users/[id]/user-admin-client.tsx
@@ -0,0 +1,344 @@
+"use client";
+import { Ban, LogIn, Shield, ShieldOff, UserCheck } from "lucide-react";
+import { useRouter } from "next/navigation";
+import { useState } from "react";
+import { toast } from "sonner";
+
+import { Panel, PanelCard } from "@/components/panel";
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+ AlertDialogTrigger,
+} from "@/components/ui/alert-dialog";
+import { Button } from "@/components/ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@/components/ui/dialog";
+import { Input } from "@/components/ui/input";
+import { Label } from "@/components/ui/label";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { Textarea } from "@/components/ui/textarea";
+
+const useRequest = () => {
+ const router = useRouter();
+ const [pending, setPending] = useState(false);
+
+ const request = async (
+ url: string,
+ init: RequestInit,
+ success: string
+ ): Promise => {
+ setPending(true);
+ try {
+ const res = await fetch(url, init);
+ const json = await res.json().catch(() => ({}));
+ if (!res.ok) {
+ toast.error(json.error ?? "Action failed.");
+ return false;
+ }
+ toast.success(success);
+ router.refresh();
+ return true;
+ } catch {
+ toast.error("Something went wrong");
+ return false;
+ } finally {
+ setPending(false);
+ }
+ };
+
+ return { pending, request };
+};
+
+export const RevokeSessionButton = ({ sessionId }: { sessionId: string }) => {
+ const { pending, request } = useRequest();
+ return (
+
+ );
+};
+
+export const UserAdminActions = ({
+ userId,
+ displayName,
+ role,
+ superAdmin,
+ banned,
+ isSelf,
+ viewerSuperAdmin,
+ sessionIds,
+}: {
+ userId: string;
+ displayName: string;
+ role: "user" | "admin";
+ superAdmin: boolean;
+ banned: boolean;
+ isSelf: boolean;
+ viewerSuperAdmin: boolean;
+ sessionIds: string[];
+}) => {
+ const router = useRouter();
+ const { pending, request } = useRequest();
+ const [banOpen, setBanOpen] = useState(false);
+ const [banReason, setBanReason] = useState("");
+ const [banExpires, setBanExpires] = useState("");
+
+ const patch = (body: Record, success: string) =>
+ request(
+ `/api/admin/users/${userId}`,
+ {
+ body: JSON.stringify(body),
+ headers: { "Content-Type": "application/json" },
+ method: "PATCH",
+ },
+ success
+ );
+
+ const handleBan = async () => {
+ const ok = await patch(
+ {
+ action: "ban",
+ banExpiresAt: banExpires
+ ? new Date(banExpires).toISOString()
+ : undefined,
+ banReason: banReason || undefined,
+ },
+ `${displayName} has been banned.`
+ );
+ if (ok) {
+ setBanOpen(false);
+ setBanReason("");
+ setBanExpires("");
+ }
+ };
+
+ const handleImpersonate = async () => {
+ const res = await fetch(`/api/admin/users/${userId}/impersonate`, {
+ method: "POST",
+ });
+ const json = await res.json().catch(() => ({}));
+ if (!res.ok) {
+ toast.error(json.error ?? "Failed to start impersonation session.");
+ return;
+ }
+ toast.success(`Now impersonating ${displayName}. Redirecting…`);
+ window.location.href = "/dashboard";
+ };
+
+ const handleRevokeAll = async () => {
+ const results = await Promise.all(
+ sessionIds.map((id) =>
+ fetch(`/api/admin/sessions/${id}`, { method: "DELETE" })
+ )
+ );
+ const failed = results.filter((r) => !r.ok).length;
+ if (failed > 0) {
+ toast.error(`Failed to revoke ${failed} session(s).`);
+ } else {
+ toast.success("All sessions revoked");
+ }
+ router.refresh();
+ };
+
+ return (
+
+
+
+
+
+
+
+
+ {viewerSuperAdmin && (
+
+ )}
+
+ {role === "user" && !superAdmin && !isSelf && (
+
+ )}
+
+ {viewerSuperAdmin && sessionIds.length > 0 && (
+
+
+
+
+
+
+ Revoke all sessions?
+
+ {displayName} will be signed out of {sessionIds.length}{" "}
+ active session(s).
+
+
+
+ Cancel
+
+ Revoke
+
+
+
+
+ )}
+
+
+ {banned ? (
+
+ ) : (
+
+ )}
+
+
+
+
+ );
+};
diff --git a/apps/web/app/admin/users/users-table.tsx b/apps/web/app/admin/users/users-table.tsx
index b3d6d3a..ab9d21d 100644
--- a/apps/web/app/admin/users/users-table.tsx
+++ b/apps/web/app/admin/users/users-table.tsx
@@ -7,11 +7,13 @@ import {
LogIn,
MoreHorizontal,
Search,
+ Settings,
Shield,
ShieldOff,
UserCheck,
UserX,
} from "lucide-react";
+import Link from "next/link";
import { useCallback, useEffect, useState } from "react";
import { toast } from "sonner";
@@ -304,9 +306,12 @@ export const UsersTable = () => {
-
+
{user.name ?? user.email}
-
+
{user.banned && (
{
+
+
+
+ Manage
+
+
+
Role
diff --git a/apps/web/app/dashboard/layout.tsx b/apps/web/app/dashboard/layout.tsx
index 1d4ee9a..479d0e7 100644
--- a/apps/web/app/dashboard/layout.tsx
+++ b/apps/web/app/dashboard/layout.tsx
@@ -1,8 +1,9 @@
+import { redirect } from "next/navigation";
import type { ReactNode } from "react";
import { SidebarProvider } from "@/components/ui/sidebar";
import { prisma } from "@/lib/db";
-import { requireUser } from "@/lib/session";
+import { getSession } from "@/lib/session";
import { AppContainer } from "./components/app-container";
import { AppSidebar } from "./components/app-sidebar";
@@ -32,13 +33,17 @@ const healthOf = (server: {
};
const DashboardLayout = async ({ children }: { children: ReactNode }) => {
- const user = await requireUser();
+ const session = await getSession();
+ if (!session?.user) {
+ redirect("/sign-in");
+ }
+ const { user } = session;
const role = (user as { role?: string }).role ?? "user";
const superAdmin = (user as { superAdmin?: boolean }).superAdmin ?? false;
- const impersonatedBy =
- (user as { impersonatedBy?: { email?: string; name?: string } | null })
- .impersonatedBy ?? null;
+ const impersonatorId =
+ (session.session as { impersonatedBy?: string | null }).impersonatedBy ??
+ null;
const ownedServers = await prisma.server.findMany({
orderBy: { createdAt: "desc" },
@@ -84,7 +89,7 @@ const DashboardLayout = async ({ children }: { children: ReactNode }) => {
}}
/>
- {impersonatedBy && (
+ {impersonatorId && (