npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

better-auth-rbac

v1.5.1

Published

A flexible Role-Based Access Control (RBAC) plugin for Better Auth that provides fine-grained permission management.

Readme

Better Auth RBAC Plugin

A flexible Role-Based Access Control (RBAC) plugin for Better Auth that provides fine-grained permission management.

Features

  • Role-based permission management
  • Granular access control
  • Easy integration with Better Auth
  • Built-in user impersonation
  • Ban/unban user management
  • Session management
  • Default role assignment

Installation

npm install better-auth-rbac

Basic Usage

Server Configuration

import { rbac } from 'better-auth-rbac';
import { betterAuth } from "better-auth";

const auth = betterAuth({
    plugins: [
        rbac()
    ]
});

Client Configuration

import { rbacClient } from "better-auth-rbac/client";

export const authClient = createAuthClient({
  plugins: [
    rbacClient()
  ]
});

Permission Checks

// Check permissions by IDs
const hasAccess = auth.api.hasPermission({
    body: {
        permissionIds: ['1', '2', '3'],
        userId: "1", // Optional: Check specific user
        roleId: '1'    // Optional: Check specific role
    }
});

// Check permissions by resource/action mapping
const hasAccess = auth.api.hasPermission({
    body: {
        permissions: {
            user: ["read", "create"],
            post: ["read"]
        },
        userId: "1"
    }
});

Customisation

import { rbac } from 'better-auth-rbac';
import { betterAuth } from "better-auth";

// Initialize Better Auth with RBAC plugin
const auth = betterAuth({
    plugins: [
        rbac({
            // Optional configuration
            defaultRoleId: '2', // Default role ID for new users
            adminRoleIds: ['1'], // Array of admin role IDs
            bannedUserMessage: "Custom ban message", // Custom message for banned users
            impersonationSessionDuration: 3600, // Duration in seconds for impersonation sessions

            // Resource permissions (optional overrides)
            resourcePermissions: {
                user: {
                    get: "fetchUser",
                    update: "modifyUser"
                },
                session: {
                    revoke: "kill_session"
                }
            },

            // Custom permission check (optional)
            hasPermission: async (input, adapter) => {
                // Admin roles bypass permission checks
                if (input.options?.adminRoleIds?.includes(input.roleId)) {
                    return true;
                }

                if (input.permissionIds) {
                    // Using your own drizzle db;
                    const permissionsList = await db.query.permissions.findMany({
                        with: {
                            rolePermissions: {
                                where: (rolePerms, { eq }) => eq(rolePerms.id, input.roleId)
                            }
                        },
                        where: (perms, { inArray }) => inArray(perms.id, input.permissionIds),
                    });
                    return permissionsList.length > 0;
                }

                return false;
            }
        })
    ]
});

API Reference

Core Endpoints

| Endpoint | Method | Description | |----------|--------|-------------| | /admin/has-permission | POST | Check if a user/role has specific permissions | | /admin/:roleId/role-permissions | GET | List permissions for a role | | /admin/update-role-permission | POST | Update role permissions | | /admin/set-role | POST | Set a user's role |

User Management

| Endpoint | Method | Description | |----------|--------|-------------| | /admin/create-user | POST | Create a new user | | /admin/update-user | POST | Update user details | | /admin/remove-user | POST | Delete a user | | /admin/set-user-password | POST | Set user's password | | /admin/ban-user | POST | Ban a user | | /admin/unban-user | POST | Unban a user |

Session Management

| Endpoint | Method | Description | |----------|--------|-------------| | /admin/list-user-sessions | POST | List user's sessions | | /admin/revoke-user-session | POST | Revoke specific session | | /admin/revoke-user-sessions | POST | Revoke all user sessions | | /admin/impersonate-user | POST | Impersonate a user | | /admin/impersonate-callback | POST | Manually impersonate a user using impersonated session's token | | /admin/stop-impersonating | POST | Stop user impersonation |

User Operations

| Endpoint | Method | Description | |----------|--------|-------------| | /admin/get-user | GET | Get user details | | /admin/list-users | GET | List users with filtering and pagination |

License

ISC