A modern web application built with Next.js that implements role-based access control (RBAC) functionality, providing secure user authentication and authorization management.
- π User Authentication - Secure login and logout functionality
- π₯ Role-Based Access Control - Different user roles with varying permissions
- π‘οΈ Route Protection - Middleware-based route protection
- π± Responsive Design - Modern UI with Tailwind CSS
- π§ͺ End-to-End Testing - Comprehensive test coverage with Playwright
- β‘ Performance Optimized - Built with Next.js 15 and Turbopack
- Framework: Next.js 15
- Runtime: React 19
- Styling: Tailwind CSS 4
- Authentication: JWT with jose library
- Testing: Playwright
- TypeScript: Full type safety
- Build Tool: Turbopack for fast development
src/
βββ app/
β βββ admin/ # Admin dashboard pages
β βββ api/ # API routes for authentication
β βββ dashboard/ # User dashboard pages
β βββ login/ # Login page and components
β βββ no-access/ # Access denied page
β βββ auth-context.tsx # Authentication context
β βββ Menu.tsx # Navigation menu component
β βββ menuConfig.ts # Menu configuration
βββ middleware.ts # Route protection middleware
βββ utils/
βββ routeRoles.ts # Role-based route definitions
- Node.js 18 or later
- npm, yarn, pnpm, or bun
- Clone the repository:
git clone <repository-url>
cd role-based-access-control-web- Install dependencies:
npm install
# or
yarn install
# or
pnpm install- Start the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev- Open http://localhost:3000 in your browser.
npm run dev- Start development server with Turbopacknpm run build- Build the application for productionnpm run start- Start the production servernpm run lint- Run ESLint for code qualitynpm run test:e2e- Run Playwright end-to-end testsnpm run test:e2e:ui- Run tests with Playwright UInpm run test:e2e:headed- Run tests in headed modenpm run test:e2e:debug- Debug tests with Playwrightnpm run test:e2e:manual- Run manual testing configuration
The application implements a comprehensive RBAC system:
- Admin: Full system access
- User: Limited dashboard access
- Viewer: Read-only access
Routes are protected using Next.js middleware, which:
- Validates JWT tokens
- Checks user roles and permissions
- Redirects unauthorized users to appropriate pages
POST /api/login- User authenticationPOST /api/logout- User logoutGET /api/me- Get current user information
The project includes comprehensive end-to-end testing with Playwright covering authentication flows, access control scenarios, navigation functionality, API endpoints, and performance metrics.
Before running tests, ensure you have the proper environment setup:
# Create environment file if it doesn't exist
echo "JWT_SECRET=your-super-secret-jwt-key-for-testing-12345" > .env.local
# Install dependencies
npm install
# Install Playwright browsers
npx playwright install chromiumDue to potential webServer auto-start issues, manual testing is recommended:
In the first terminal window:
npm run devWait for the server to start completely. You should see output like:
β² Next.js 15.3.4
- Local: http://localhost:3000
β Ready in 2.1s
In a second terminal window:
# Run all tests
npx playwright test --config=playwright.manual.config.ts
# Run specific test file
npx playwright test --config=playwright.manual.config.ts e2e/basic.spec.ts
# Use UI mode (recommended for debugging)
npx playwright test --config=playwright.manual.config.ts --ui
# Run with browser visible
npx playwright test --config=playwright.manual.config.ts --headedFor convenience, you can also use the automated test script:
# Run all tests automatically
npm run test:e2e
# Run tests with UI
npm run test:e2e:ui
# Debug tests
npm run test:e2e:debugBefore running tests, ensure:
- β
.env.localfile exists withJWT_SECRET - β
All dependencies installed (
npm install) - β
Playwright browsers installed (
npx playwright install) - β
Application builds successfully (
npm run build)
- Basic Tests (
e2e/basic.spec.ts) - Application core functionality - Authentication (
e2e/auth.spec.ts) - Login/logout workflows - Access Control (
e2e/access-control.spec.ts) - Role-based permissions - Navigation (
e2e/navigation.spec.ts) - UI navigation and interface - API Tests (
e2e/api.spec.ts) - Backend endpoint validation - Performance (
e2e/performance.spec.ts) - Page load performance
- Use
--headedto see browser actions in real-time - Use
--uifor interactive debugging mode - Add
await page.pause()in test code for breakpoints - View test reports:
npx playwright show-report - Check browser console logs in headed mode
Tests are configured to run automatically in GitHub Actions. The CI pipeline will:
- Set up the environment
- Install dependencies and browsers
- Build the application
- Run the full test suite
- Generate and publish test reports
- ESLint configuration for code standards
- TypeScript for type safety
- Tailwind CSS for consistent styling
The application supports various environment configurations for development, testing, and production.
npm run build
npm run startThe easiest way to deploy is using the Vercel Platform:
- Connect your repository to Vercel
- Configure environment variables
- Deploy automatically on every push
This project is private and proprietary.
For support and questions, please open an issue in the repository.