This Gist outlines the core logic powering the BBQ Heaven Rockingham ordering ecosystem, focusing on security, location-aware ordering, and real-time synchronization.
The system leverages Firebase Authentication and Realtime Database Rules to enforce Role-Based Access Control:
- Customers: Granted
Write-Onlyaccess to theordersnode. This allows order submission while preventing customers from viewing other people's data. - Staff/Admin: Validated via a custom
roleattribute in theusersnode. Only authenticatedadminUIDs can read the live order stream on the Kitchen Dashboard. - Data Integrity: Strict type-casting in
order-system.jsensures values like pricing and quantities are validated before being written to the NoSQL database.
To prevent accidental orders from users outside of Western Australia (common due to mobile IP routing to Eastern States), we use the Web Geolocation API:
- Logic: Uses the Haversine Formula to calculate the mathematical distance between the user’s device and the Rockingham smokehouse.
- Radius Lock: A strict 60km limit is enforced (covering Perth to Mandurah).
- UI Response: If the user is outside the zone, the system dynamically disables the "Place Order" button and updates the UI to "PICKUP ONLY (OUTSIDE AREA)".
Built on Firebase Realtime Database (NoSQL), the system maintains a sub-second "Customer-to-Pit Pipeline":
- WebSocket Protocol: Unlike REST APIs, the
onValuelistener keeps a bi-directional connection open. - Performance: When a customer clicks "Place Order," the kitchen monitor reflects the change in <200ms, allowing staff to react instantly.
The site footer features dynamic data powered by Supabase Presence and AWST-Aware Logic:
- Tracking: Uses Supabase Channels to track active browser sessions.
- Session IDs: Generates a random alphanumeric
sessionIdper tab to differentiate between mobile and desktop users. - Instant Updates: The
.on('presence', { event: 'sync' })listener automatically updates the#user-countelement in the footer as visitors join or leave.
- Perth Time: Uses
Intl.DateTimeFormatto calculate status based on Australia/Perth time, ignoring the user's local system clock. - Split Schedules: Accounts for complex split-shift hours (e.g., Wednesday lunch and dinner windows).
- Dynamic UI: Includes a CSS-animated pulse indicator and context-aware hints (e.g., "Re-opens at 5:00 PM").
To initialize the footer logic, import the utilities into your main.js:
import { initLiveCounter, updateBusinessStatus } from './realtime-utils.js';
// Start presence tracking
initLiveCounter();
// Set initial status and refresh every 60 seconds
updateBusinessStatus();
setInterval(updateBusinessStatus, 60000);/* Animated Pulse for Live Status */
.animate-ping {
animation: ping 1.5s cubic-bezier(0, 0, 0.2, 1) infinite;
}
@keyframes ping {
75%, 100% {
transform: scale(2);
opacity: 0;
}
}