A Next.js frontend application for the disaster detection system that connects to a backend API for real-time monitoring and user management.
- User Authentication: Login, signup, logout, and token management
- Profile Management: View and update user profiles
- CCTV Monitoring: Real-time CCTV feed monitoring with disaster detection
- Location-based Services: District and city-based filtering
- Responsive Design: Mobile-friendly interface
This frontend connects to the following backend API endpoints:
POST /members/auth/login- User loginPOST /members/auth/signup- User registrationPOST /members/me/logout- User logoutPOST /members/auth/reissue- Token refreshGET /members/me- Get user profilePATCH /members/me- Update user profilePATCH /members/me/password- Change passwordGET /members/{id}- Get member by IDDELETE /members/{id}- Delete memberGET /members/search- Search members by address
GET /cctvs- Get all CCTVsPOST /cctvs- Create/update CCTVPOST /cctvs/table- Create CCTV tableDELETE /cctvs/table- Delete CCTV tablePOST /cctvs/import-csv- Import CCTV data from CSVGET /cctvs/{id}- Get CCTV by IDDELETE /cctvs/{id}- Delete CCTVGET /cctvs/{id}/stream- Get CCTV stream URLGET /cctvs/districts- Get all districtsPOST /cctvs/export- Export CCTV data to CSV
-
Clone the repository
git clone <repository-url> cd disaster-detection-frontend
-
Install dependencies
npm install # or pnpm install -
Environment Configuration
Copy the example environment file:
cp .env.local.example .env.local
Update the environment variables in
.env.local:# Backend API Configuration API_BASE_URL=http://your-backend-url:8080 NEXT_PUBLIC_API_BASE_URL=http://your-backend-url:8080 # Firebase Configuration (if needed) NEXT_PUBLIC_FIREBASE_VAPID_KEY=your_vapid_key_here
-
Run the development server
npm run dev # or pnpm dev -
Open your browser Navigate to http://localhost:3000
app/
├── admin/ # Admin panel for CCTV management
├── components/ # Reusable UI components
├── contexts/ # React contexts (AuthContext)
├── hooks/ # Custom React hooks (useAuth)
├── services/ # API service layer (direct backend connection)
├── utils/ # Utility functions (auth management)
├── login/ # Login page
├── signup/ # Signup page
├── profile/ # Profile management page
└── disaster-simulation/ # Disaster simulation page
Centralized API client that handles all backend communication with proper error handling and authentication.
Manages JWT tokens, user data, and authentication state with automatic token refresh.
React context provider that makes authentication state available throughout the app.
useAuth- Authentication state managementuseToast- Toast notifications
- User logs in with phone number and password
- Backend returns access and refresh tokens
- Tokens are stored in localStorage
- API requests include Authorization header
- Automatic token refresh on expiration
- Logout clears all stored data
The application fetches CCTV data from the backend and displays:
- Real-time camera feeds
- Disaster detection status
- Location-based filtering
- Interactive map interface
- The app uses Next.js 14 with App Router
- UI components are built with shadcn/ui
- Map functionality uses Leaflet
- Authentication uses JWT tokens
- All API calls go through the service layer for consistency
-
Build the application:
npm run build
-
Set production environment variables
-
Deploy to your preferred hosting platform
-
Ensure backend API is accessible from the frontend domain
- CORS Errors: Ensure backend allows requests from frontend domain
- Token Expiration: Check token refresh logic and backend token validity
- API Connection: Verify
API_BASE_URLenvironment variable - Map Not Loading: Check Leaflet CSS import and component mounting
Enable debug logging by setting:
NODE_ENV=development- Follow the existing code structure
- Use TypeScript for type safety
- Add proper error handling
- Update this README for new features