Skip to content

Role Based Access Control Boilerplate for Next.js

License

Notifications You must be signed in to change notification settings

justin22/nextjs-rbac

Repository files navigation

This is a Next.js project bootstrapped with create-next-app.

Introduction

Next.js - RBAC (Role Based Access Control) helps to setup a application, with roles and permissions. This boilerplate ships with RBAC database schema, utility functions for RBAC and very minimal or no components and styles.

Main functionalities are as follows,

  1. Setup Teams
  2. Setup Roles & Permissions for teams
  3. Assign roles to users

RBAC Table structure

Dependencies

  1. prisma
  2. next-auth

Authentication

next-auth is used login and session management in the project. This boilerplate ships with Google provider. But you can add more providers, refer next-auth docs for more info.

Database setup

This boilerplate comes with prisma as the database Adapter. Refer to the prisma docs to connect to your database.

Following is an example for Postgres. Once you have a Database setup, add DATABASE_URL to your env file.

DATABASE_URL"postgresql://mydbuser:123@localhost:5432/mydb?schema=public"

Run migrations

Once database setup is done, you can run the migration using prisma command.

npx prisma migrate dev

Start dev server

npm run dev
# or
yarn dev
# or
pnpm dev

Open http://localhost:3000 with your browser to see the result.

Application flow.

RBAC Table structure

Todo

  • Integrate next-auth
  • Setup teams, roles and permissions
  • Create guard (something like can(user, 'PERMISSION_NAME'))
  • Ability to invite users, accept/decline invites
  • Switch teams
  • Unit tests

About

Role Based Access Control Boilerplate for Next.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published