authClient.admin.hasPermission always returns 401 unauthorized

Hey, i'm using the auth plugin,

The api/auth/admin/has-permission endpoint always returns 401 even though i'm logged in. I have custom roles

import { createAccessControl } from 'better-auth/plugins/access';

/**
 * make sure to use `as const` so typescript can infer the type correctly
 */
const statement = {
  events: ['create', 'read', 'update', 'delete'],
  event: ['manage'],
  users: ['manage'],
  participants: ['create', 'read', 'update', 'delete'],
} as const;

export const ac = createAccessControl(statement);

export const superAdmin = ac.newRole({
  events: ['create', 'read', 'update', 'delete'],
});

export const eventAdmin = ac.newRole({
  event: ['manage'],
  users: ['manage'],
  participants: ['create', 'read', 'update', 'delete'],
});

export const secretary = ac.newRole({
  participants: ['create', 'read', 'update', 'delete'],
});

export const roles = {
  superAdmin,
  eventAdmin,
  secretary,
};
Was this page helpful?