Better Auth Roles and Permissions: When to Add a Policy Engine

- Share:





3366 Members
Better Auth is a popular auth stack for TypeScript apps. Its organization plugin ships createAccessControl, role helpers, and hasPermission. The docs also cover dynamic access control (dynamicAccessControl: { enabled: true }) for database-backed org roles. That is a solid organization RBAC story.
This post is for developers already on Better Auth who are outgrowing owner / admin / member. It stays fair to the plugin. Better Auth is a good authentication layer. The question is when organization statements stop being enough for authorization, and how to add a policy engine without throwing away what you have.
Out of the box, organizations get three roles:
You define a statement map, build roles with createAccessControl, and check with auth.api.hasPermission or the client helper:
import { betterAuth } from "better-auth";
import { organization } from "better-auth/plugins";
import { createAccessControl } from "better-auth/plugins/access";
const statement = {
project: ["create", "share", "update", "delete"],
} as const;
const ac = createAccessControl(statement);
const member = ac.newRole({ project: ["create"] });
const admin = ac.newRole({ project: ["create", "update"] });
const owner = ac.newRole({
project: ["create", "update", "delete"],
});
export const auth = betterAuth({
plugins: [
organization({
ac,
roles: { member, admin, owner },
dynamicAccessControl: { enabled: true },
}),
],
});
await auth.api.hasPermission({
headers: await headers(),
body: {
permissions: { project: ["create"] },
},
});
For many B2B apps, that is enough for a long time: invite members, assign org roles, gate settings screens, allow who can create a project at the org level.
Dynamic access control adds org-specific roles stored in the database, with async hasPermission that loads them. That closes a real gap for customers who need custom role names without redeploying statement code.
Better Auth is clear about some edges. Client-side checkRolePermission is static. It does not include dynamic roles. Use hasPermission when dynamic roles matter.
More important for product design: organization statements answer "does this member's org role include this permission?" They do not, by themselves, answer:
Those are resource-level relationships (ReBAC) and attribute conditions (ABAC). You can approximate some of them with more statement keys, but you end up encoding a policy graph into flat permission strings and custom tables beside Better Auth. At that point you are building a policy engine by accident.
Issue threads asking for dynamic roles in more plugins show a common pattern: teams like the auth ergonomics, then need authorization that is resource-specific and attribute-aware. That is normal. It is not a failure of Better Auth.
For model vocabulary, see RBAC vs ABAC vs ReBAC.
A clean split:
| Concern | Keep in Better Auth | Move to a policy engine (Permit) |
|---|---|---|
| Sign-up, sessions, OAuth, passkeys | Yes | No |
| Org membership and invitations | Yes | Mirror members as users/tenants |
| Coarse org roles for admin UI | Often yes | Optional sync |
| Per-project / per-document roles | Painful | Yes (ReBAC) |
| Attribute conditions | Hand-rolled | Yes (ABAC with a locally deployed PDP today; Cloud PDP support coming soon) |
| Central audit of allow/deny | App-specific | Decision logs |
Sync pattern:
auth.api.getSession, call permit.check.import { Permit } from "permitio";
import { auth } from "@/lib/auth";
import { headers } from "next/headers";
const permit = new Permit({
token: process.env.PERMIT_API_KEY!,
pdp: process.env.PERMIT_PDP_URL ?? "http://localhost:7766",
});
export async function updateProject(projectId: string, patch: unknown) {
const session = await auth.api.getSession({ headers: await headers() });
if (!session) throw new Error("Unauthorized");
const tenant = session.session.activeOrganizationId;
if (!tenant) throw new Error("No active organization");
const allowed = await permit.check(session.user.id, "update", {
type: "project",
key: projectId,
tenant,
});
if (!allowed) throw new Error("Forbidden");
// mutate project...
}
Sync only stable identifiers and the attributes your policies need (user id, org/tenant id, role names). Do not copy full Better Auth profile records into the policy store. See the PDP overview for how checks reach a local or cloud PDP (a locally deployed PDP evaluates checks with no remote SaaS call, and OPAL keeps its policy and data current), and the user/tenant sync guides on docs.permit.io when wiring membership changes.
You still use Better Auth cookies and organization plugins for login and invites. Permit answers the resource question. For why teams stop rebuilding that second half, see Stop rebuilding permissions. Similar auth-plus-policy splits show up in Supabase RBAC.
Model in Permit (control plane):
project with actions read, update, delete, manage_memberseditor / viewer from user to projecteditor can update; viewer can readapprove_payment allowed when resource.amount <= user.approval_limitFor ABAC, run a locally deployed PDP today, then either sync approval_limit onto the user in Permit or pass amount (and any other needed attributes) on the resource object in permit.check so the PDP sees them at decision time.
Assign relationships when someone is added to a project (your app code calls the Permit API). Checks stay one line in the handler. Org-level "can create projects" can remain a Better Auth hasPermission on project: ["create"] if you like. Instance-level "can edit project 88" goes to Permit.
| Your need | Stay on organization plugin | Add a policy engine |
|---|---|---|
| Owner / admin / member only | Yes | Not yet |
| Custom org roles, still org-wide | Dynamic access control | Not yet |
| Permissions differ per project, doc, or workspace | Temporary hacks only | Yes |
| Approvals with attributes (amount, region, risk) | Hard | Yes (locally deployed PDP today) |
| Agents or services with explicit scoped delegation, not inherited user permissions | Poor fit | Yes |
| Auditors want allow/deny evidence per action | DIY logs | PDP decision logs (see Why was this allowed?) |
Better Auth does not need to become a full fine-grained authorization product to stay valuable. Authentication suites that also try to be Zanzibar usually create a second, half-finished policy system. Using Better Auth for identity and org membership, then a purpose-built authorization layer for resource policy, is a complementary design that keeps each system focused on what it does best.
If you are still happy inside organization statements, ship. When you hear yourself say "this permission depends on which project," it is time to add a policy engine beside Better Auth, not to twist the plugin into one.

Co-Founder & VP of R&D at Permit.io