- Add UserQRCode component to display unique QR code on user profile - Add QRCodeScanner component for mobile camera-based scanning - Create EventCheckInPage for organizers to scan attendee QR codes - Add backend endpoint POST /api/events/:id/checkin for check-in - Add check-in button to EventDetailModal for organizers - Install qrcode.react and html5-qrcode dependencies - Implement real-time attendee list updates - Add organizer permission validation - Prevent duplicate check-ins - Mobile-optimized with back camera support
6.2 KiB
6.2 KiB
QR Code Check-In System Implementation
Overview
Implemented a QR code-based check-in system for event attendees. Event organizers can scan attendee QR codes from their mobile devices to track attendance at cleanup events.
Features
1. User QR Code Display
- Location: User Profile Page (Overview tab)
- Component:
UserQRCode(src/components/user/UserQRCode.tsx) - Each user has a unique QR code containing their Clerk user ID
- QR code is displayed prominently on their profile for easy access
- Users can show this QR code to event organizers for check-in
2. QR Code Scanner
- Component:
QRCodeScanner(src/components/event/QRCodeScanner.tsx) - Uses
html5-qrcodelibrary for camera-based scanning - Mobile-optimized with back camera support
- Real-time scanning with visual feedback
- Error handling for invalid QR codes
3. Event Check-In Page
- Route:
/events/:eventId/checkin - Component:
EventCheckInPage(src/pages/EventCheckInPage.tsx) - Access: Only event organizers can access
- Features:
- Live QR code scanner
- List of registered attendees
- Visual indication of checked-in attendees
- Real-time updates after successful check-in
- Success/error notifications
4. Backend API
- Endpoint:
POST /api/events/:id/checkin - Controller:
eventController.checkInAttendee - Service:
eventService.checkInAttendee - Validates:
- User is the event organizer
- Attendee is registered for the event
- Attendee hasn't already checked in
- Returns attendee information on successful check-in
User Flow
For Attendees:
- Navigate to their profile page
- View their personal QR code in the Overview tab
- Show QR code to event organizer at the event
For Organizers:
- Navigate to their event details
- Click "QR Code Check-In" button
- Grant camera permissions
- Click "Start Scanning"
- Point camera at attendee's QR code
- System automatically checks in the attendee
- Visual confirmation and attendee list updates
Technical Implementation
Dependencies Added:
{
"qrcode.react": "^3.x.x",
"html5-qrcode": "^2.x.x",
"@types/qrcode.react": "^1.x.x"
}
QR Code Data Format:
{
"userId": "clerk_user_id",
"type": "attendee-checkin",
"timestamp": 1234567890
}
Key Components:
-
UserQRCode.tsx
- Generates QR code using
qrcode.react - High error correction level (H)
- 200x200px size with margin
- Displays user's name below QR code
- Generates QR code using
-
QRCodeScanner.tsx
- Uses Html5Qrcode for camera access
- 250x250px scanning box
- 10 FPS scanning rate
- Parses and validates QR code data
- Callbacks for successful scan and errors
-
EventCheckInPage.tsx
- Fetches event and attendee data
- Verifies organizer permissions
- Manages scanner state
- Handles check-in API calls
- Updates UI in real-time
Backend Changes:
-
eventController.ts
- Added
checkInAttendeemethod - Validates organizer permissions
- Finds or creates user from Clerk ID
- Calls service layer for check-in
- Added
-
eventService.ts
- Added
checkInAttendeemethod - Validates registration status
- Prevents duplicate check-ins
- Updates attendance record
- Added
-
eventRoutes.ts
- Added
POST /:id/checkinroute - Protected with
requireAuthmiddleware
- Added
UI/UX Enhancements
User Profile:
- QR code card with clear instructions
- Prominent placement in Overview tab
- User identification below QR code
Check-In Page:
- Mobile-responsive design
- Large, easy-to-use scanner interface
- Clear start/stop buttons
- Real-time attendee list with check-in status
- Color-coded status indicators (green for checked in)
- Success/error toast notifications
Event Detail Modal:
- Added "QR Code Check-In" button for organizers
- Purple button with QR icon
- Available before and after event date
- Navigates to dedicated check-in page
Security Considerations
- Authorization: Only event organizers can access check-in page
- Validation: Backend validates all check-in requests
- QR Code Format: Structured JSON with type validation
- Timestamp: Included in QR code (not currently validated, but available for future use)
Mobile Optimization
- Camera access optimized for mobile devices
- Back camera selected by default
- Responsive layout for small screens
- Touch-friendly buttons and controls
- Large scanning area for easy targeting
Future Enhancements
- Offline Support: Cache attendee list for offline check-in
- Bulk Check-In: Allow manual selection of multiple attendees
- Check-In History: Track check-in timestamps
- QR Code Expiry: Add time-based validation to QR codes
- Export: Generate check-in reports
- Notifications: Send confirmation to attendees upon check-in
Testing
Manual Testing Checklist:
- User can view their QR code on profile page
- QR code scanner requests camera permission
- Scanner successfully reads QR codes
- Only organizers can access check-in page
- Check-in updates attendee status
- Duplicate check-ins are prevented
- Error messages display correctly
- Mobile camera works properly
- Attendee list updates in real-time
Files Modified/Created
Frontend:
src/components/user/UserQRCode.tsx(new)src/components/user/index.ts(new)src/components/event/QRCodeScanner.tsx(new)src/pages/EventCheckInPage.tsx(new)src/pages/UserProfilePage.tsx(modified)src/components/event/EventDetailModal.tsx(modified)src/App.tsx(modified)package.json(modified)
Backend:
server/src/controllers/eventController.ts(modified)server/src/services/eventService.ts(modified)server/src/routes/eventRoutes.ts(modified)
Deployment Notes
- Ensure camera permissions are properly configured in production
- HTTPS required for camera access in browsers
- Test on various mobile devices and browsers
- Consider rate limiting for check-in endpoint
- Monitor for QR code scanning performance issues
Support
For issues or questions:
- Check browser camera permissions
- Ensure HTTPS is enabled
- Verify user is registered for the event
- Check that user is the event organizer
- Review browser console for errors