This project contains all the necessary boilerplate to setup a multi-tenant SaaS with Next.js including authentication and RBAC authorization.
- Node.js 14.x
- Yarn 1.x
- Docker
- Docker Compose
- Git
- GitHub account
- GitHub OAuth application
- Clone the repository:
git clone
- Install dependencies:
yarn
- Create a
.env
file based on.env.example
:
cp .env.example .env
- Fill in the environment variables:
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/saas?schema=public"
GITHUB_OAUTH_CLIENT_ID=""
GITHUB_OAUTH_CLIENT_SECRET=""
GITHUB_OAUTH_REDIRECT_URL="http://localhost:3000/api/auth/callback"
JWT_SECRET="jwtSecretKey"
JWT_EXPIRES_IN="1d"
NEXT_PUBLIC_API_URL="http://localhost:3333"
- Start the database:
docker-compose up -d
- Run the migrations:
yarn prisma migrate dev
- Start the development server:
yarn dev
- Access the application at
http://localhost:3000
. - Access the API at
http://localhost:3333
.
- It should be able to authenticate using e-mail & password;
- It should be able to authenticate using Github account;
- It should be able to recover password using e-mail;
- It should be able to create an account (e-mail, name and password);
- It should be able to create a new organization;
- It should be able to get organizations to which the user belongs;
- It should be able to update an organization;
- It should be able to shutdown an organization;
- It should be able to transfer organization ownership;
- It should be able to invite a new member (e-mail, role);
- It should be able to accept an invite;
- It should be able to revoke a pending invite;
- It should be able to get organization members;
- It should be able to update a member role;
- It should be able to get projects within a organization;
- It should be able to create a new project (name, url, description);
- It should be able to update a project (name, url, description);
- It should be able to delete a project;
- It should be able to get billing details for organization ($20 per project / $10 per member excluding billing role);
Roles & permissions.
- Owner (count as administrator)
- Administrator
- Member
- Billing (one per organization)
- Anonymous - (pending...)
Administrator | Member | Billing | Anonymous | |
---|---|---|---|---|
Update organization | β | β | β | β |
Delete organization | β | β | β | β |
Invite a member | β | β | β | β |
Revoke an invite | β | β | β | β |
List members | β | β | β | β |
Transfer ownership | β | β | β | |
Update member role | β | β | β | β |
Delete member | β | β | β | |
List projects | β | β | β | β |
Create a new project | β | β | β | β |
Update a project | β | β | β | |
Delete a project | β | β | β | |
Get billing details | β | β | β | β |
Export billing details | β | β | β | β |
β = allowed β = not allowed
β οΈ = allowed w/ conditions
- Only owners may transfer organization ownership;
- Only administrators and project authors may update/delete the project;
- Members can leave their own organization;