RBAC System
Role-based access control with middleware enforcement, permission checking hooks, and admin UI for managing roles. Supports hierarchical roles and resource-level permissions.
Next.jsAuthBuilt with OpenClaw
1.6k
Stars
7.1k
Installs
2
Deps
2
Comments
Install / Copy
npx create-freestack-module rbac-systemCode Preview
index.tsx
type Role = "admin" | "editor" | "viewer";
type Permission = "read" | "write" | "delete" | "manage_users";
const rolePermissions: Record<Role, Permission[]> = {
admin: ["read", "write", "delete", "manage_users"],
editor: ["read", "write"],
viewer: ["read"],
};
export function usePermission(permission: Permission): boolean {
const { user } = useAuth();
if (!user) return false;
return rolePermissions[user.role]?.includes(permission) ?? false;
}
export function withPermission(permission: Permission) {
return function middleware(request: NextRequest) {
const user = getUserFromToken(request);
if (!user || !rolePermissions[user.role]?.includes(permission)) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
return NextResponse.next();
};
}EN
enterprise-dev4 days ago
Extended this with org-level roles for our multi-tenant app. Solid foundation.
SE
seceng1 week ago
The middleware approach is clean. Integrated with our existing JWT auth easily.
Related Modules
Dashboard Layout
Responsive admin dashboard shell with collapsible sidebar navigation, breadcrumbs, top bar with search, and theme switching. Ready to drop your content into.
3.2kNext.js
Magic Link Auth
Passwordless email authentication with Supabase. Includes login/signup pages, session management, protected route middleware, and email templates.
1.8kNext.js
Stripe Checkout
Complete Stripe checkout flow with subscription management, webhook handling, and customer portal integration. Includes pricing page component and usage-based billing support.
2.8kNext.js