From 0e4f6c4b01b248e66035fdefb53ea73f46aec446 Mon Sep 17 00:00:00 2001 From: dmitriylaukhin Date: Sat, 25 Apr 2026 13:18:49 +0500 Subject: [PATCH] Fix impersonation: use direct fetch to /api/auth/admin/impersonate-user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit authClient.admin.impersonateUser is not registered in pathMethods in better-auth v1.6 client plugin — call the endpoint directly. Co-Authored-By: Claude Sonnet 4.6 --- src/components/admin/users-table.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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); } }