This project is a Next.js application that implements a dashboard with role-based access control (RBAC). It includes features such as user authentication, admin panel, and role-specific access to different parts of the application.
admin credentials email: francismwanik254@gmail.com pass: francismwanik254@gmail.com
- Admin creates an invite for a user with a specific role.
- The user receives an email with a link to register.
- The user registers and logs in.
- The user can now access the application based on their role.
- User authentication (login/logout)
- Role-based access control (Admin, Technician, Driver, Customer)
- Admin dashboard
- Secure API routes
- Edge Runtime compatible JWT authentication
Before you begin, ensure you have met the following requirements:
- Node.js (v14 or later)
- npm or yarn
- A PostgreSQL database (for Prisma ORM)
-
Clone the repository:
git clone git@github.com:Francis-Mwaniki/Nextjs-14-RBA.git cd Nextjs-14-RBA
-
Install the dependencies:
npm install
or
yarn install
-
Set up the database:
npx prisma migrate dev
-
(Optional) Seed the database with initial data:
npx prisma db seed
To run the development server:
npm run dev
or
yarn dev
Create a .env
file in the root directory and add the following:
DATABASE_URL=
JWT_SECRET=
BREVO_SMTP_HOST=
BREVO_SMTP_PORT=
BREVO_SMTP_PASSWORD=
BREVO_SMTP_USER=
To create the first admin user, navigate to the /setup
route in your browser. This route is only accessible when there are no users in the database.
Use the email and password of the admin user you created to log in at the /login
route.
- Admin Dashboard:
/admin
- Technician Area:
/technician
- Driver Area:
/driver
- Customer Area:
/customer
Access to these areas is controlled by the user's role.
/pages
or/app
: Contains the Next.js pages/routes/components
: Reusable React components/lib
: Utility functions and shared logic/prisma
: Database schema and migrations/public
: Static files/styles
: Tailwind CSS
/api/auth/login
: Handles user login/api/auth/logout
: Handles user logout/api/users
: CRUD operations for users (admin only)/api/[other-resources]
: Other API routes for your application
Contributions to this project are welcome. Please ensure you follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License.
Francis Mwaniki - francismwaniki630@gmail.com
Project Link: https://github.com/Francis-Mwaniki/Nextjs-14-RBA