Example apps
Two complete apps live in the examples/ folder of the repository. Both use a SQLite file, so they run without any database server, and both use a fake login: you pick a demo user and it is stored in a cookie. Swap that part for your real authentication.
Each app seeds the same roles and users:
| User | Role | Permissions |
|---|---|---|
| #1 Alice Admin | admin | everything, including manage users and delete articles |
| #2 Eddie Editor | editor | view articles, create articles, edit articles, publish articles |
| #3 Vera Viewer | viewer | view articles |
| #4 Nora Nobody | — | nothing |
Because the session is just a demo_user=<id> cookie, you can call the APIs as any user with curl:
curl -i -b demo_user=3 http://localhost:3000/api/articles # 200
curl -i -b demo_user=4 http://localhost:3000/api/articles # 403 FORBIDDENNext.js + Prisma
examples/next-prisma — Next.js 15 App Router, Prisma on SQLite, @anievo-id/rbac-evolution-next and @anievo-id/rbac-evolution-react.
app/layout.tsxpassesawait getSnapshot()to<RbacProvider>; the articles page hides buttons with<Can>and<Cannot>.- Server actions are wrapped in
withPermission()andwithRole(). A "Bypass the UI" button calls an action directly, so you can see the server refuse it. /adminis protected bymiddleware.ts(createRbacMiddlewarewith therbacinstance on the Node.js runtime) and again byrequireRole('admin')in the page.app/api/articlesroute handlers usewithRbac()and answer401/403JSON.rbac.config.tslets you run the CLI, e.g.rbac-evolution show.- Storage: the Prisma adapter, with the rbac models copied into
prisma/schema.prisma.
pnpm install
pnpm turbo run build --filter=rbac-evolution-example-next-prisma^...
pnpm --filter rbac-evolution-example-next-prisma db:setup
pnpm --filter rbac-evolution-example-next-prisma dev # http://localhost:3000Vue 3 + Express
examples/vue-express — an Express 5 API with @anievo-id/rbac-evolution-express and Drizzle on SQLite (libsql), plus a Vite + Vue 3 SPA with @anievo-id/rbac-evolution-vue.
- The API attaches
req.rbacwithrbacMiddleware()and guards routes withrequirePermission()andrequireRole(). - Storage: the Drizzle adapter (
sqliteRbacSchema()+drizzleSqliteAdapter(db)). The tables are created from the SQL file shipped with the package. - The SPA loads
{ user, snapshot }fromGET /api/meand callsrbac.setSnapshot(snapshot). Templates usev-can,v-can.not,v-roleand<Can>with a#fallbackslot. - Routes declare
meta: { permission }ormeta: { role }, checked inrouter.beforeEach. - The
fetchwrapper sends you to/loginon401and shows the server's message on403.
pnpm install
pnpm turbo run build --filter=rbac-evolution-example-vue-express^...
pnpm --filter rbac-evolution-example-vue-express db:setup
pnpm --filter rbac-evolution-example-vue-express dev # SPA on http://localhost:5173, API on :4000UI checks are not security
In both apps, <Can>, v-can and the router guards only decide what the UI shows. Every action is checked again on the server — that is what the "Bypass the UI" buttons demonstrate.
