listUsers returns status 401 UNAUTHORIZED even though the current user is an admin.

I am using the admin() and adminClient() plugins while testing out better-auth. I am trying to list out the users using the auth client, but I am getting a 401 unauthorized. I've registered a user and manually changed the role to admin in the database. I am using nextjs15

Here's the code:
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { authClient } from "@/lib/auth-client";
import { verifySession } from "@/lib/verify-session";

export default async function UsersPage() {
  const { user } = await verifySession();

  console.log("CURRENT USER: ", user);

  const { data } = await authClient.admin.listUsers({
    query: {
      limit: 10,
      offset: 0,
    },
  });

  const users = data?.users;

  return (
    <div className="space-y-4">
      <h1 className="text-3xl font-bold">Users</h1>
      <Card>
        <CardHeader>
          <CardTitle>Users</CardTitle>
        </CardHeader>
        <CardContent>
          <ul>
            {users && users.map((user) => <li key={user.id}>{user.email}</li>)}
          </ul>
        </CardContent>
      </Card>
    </div>
  );
}


Here are the console logs:
CURRENT USER:  {
  id: 'ZjLohn28IT3OHklqxwAdspRV1Om2X0Ss',
  name: 'xxxx',
  email: 'xxx@gmail.com',
  emailVerified: true,
  image: null,
  createdAt: 2025-02-07T10:24:09.645Z,
  updatedAt: 2025-02-07T10:24:09.645Z,
  role: 'admin',
  banned: null,
  banReason: null,
  banExpires: null
}
 โœ“ Compiled /api/auth/[...all] in 180ms (1197 modules)
 GET /api/auth/admin/list-users?limit=10&offset=0 401 in 345ms


What am I missing? ๐Ÿ˜…
Was this page helpful?