diff --git a/src/components/admin/users-table.tsx b/src/components/admin/users-table.tsx index 3fdd221..ee62aff 100644 --- a/src/components/admin/users-table.tsx +++ b/src/components/admin/users-table.tsx @@ -1,10 +1,8 @@ "use client"; import { useState } from "react"; -import { useRouter } from "next/navigation"; import Link from "next/link"; import { Badge } from "@/components/ui/badge"; -import { authClient } from "@/lib/auth-client"; type Enrollment = { courseId: string; @@ -93,15 +91,21 @@ function UserPopup({ user }: { user: UserRow }) { } function ImpersonateButton({ userId }: { userId: string }) { - const router = useRouter(); const [loading, setLoading] = useState(false); async function handleImpersonate() { setLoading(true); try { - await authClient.admin.impersonateUser({ userId }); + const res = await fetch("/api/auth/admin/impersonate-user", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ userId }), + credentials: "include", + }); + if (!res.ok) throw new Error(await res.text()); window.location.href = "/dashboard"; - } catch { + } catch (e) { + console.error("Impersonation failed:", e); setLoading(false); } }