Overview
Guests receive a QR code at check-in that grants them access to the incident reporting system. The QR code contains an access code linked to their room and reservation.QR code authentication eliminates the need for guests to remember passwords while maintaining security through time-limited access codes.
How It Works
QR Code Generation
The hotel generates a QR code for each guest containing a unique access code linked to their room reservation.
Implementation
The QR scanning functionality is implemented in thescan.tsx screen using Expo Camera:
scan.tsx
Camera Permissions
The app requests camera permissions before scanning:Permission Flow
Permission Flow
- Check if permission is already granted
- Request permission if needed
- Display alert if permission is denied
- Enable scanning once permission is granted
Scanning Process
The camera view is configured to detect QR codes and handle the scan result:Scan Lock Mechanism
To prevent multiple scans, a ref-based lock is used:The scan lock prevents duplicate processing if the camera detects the same QR code multiple times.
Data Validation
The scanned data is parsed and validated:The code supports both JSON format (
{"access_code": "..."}}) and plain text format for flexibility.Session Verification
The access code is verified against the database:Validation Checks
Access Code Match
Verifies the code exists in the database
Active Status
Ensures the session is currently active
Expiration Check
Validates the session hasn’t expired
Room Link
Confirms the session is linked to a valid room
Expiration Handling
The app checks if the session has expired:Expired sessions require guests to obtain a new QR code from hotel staff.
Session Storage
Successful scans store the session data securely:access_code: The unique access coderoom_id: Link to the guest’s roomexpires_at: Session expiration timestampactive: Whether the session is active
Camera UI
The scanning interface includes a visual frame and helper text:styles
Error Handling
The scanning process handles multiple error scenarios:Permission Denied
Permission Denied
Displays an alert explaining why camera access is needed.
Invalid QR Code
Invalid QR Code
Shows error message and allows retry by unlocking the scan.
Expired Session
Expired Session
Informs the guest the code has expired and needs replacement.
Already Used
Already Used
Validates the session is still active and hasn’t been deactivated.
Database Schema
The guest_sessions table structure:Security Features
Secure Storage
Sessions are stored using Expo SecureStore with encryption
Time-Limited Access
Sessions expire automatically to prevent unauthorized access
One-Time Use
Access codes can be deactivated after check-out
Room Isolation
Each session is linked to a specific room
Best Practices
- Always validate permissions before attempting to scan
- Use scan locks to prevent duplicate processing
- Handle all error cases with user-friendly messages
- Store sessions securely using SecureStore
- Validate expiration on both client and server
Related Features
Guest Sessions
Learn about session management
Security
Understand security measures