66// 2. Setting up HTTP referrer restrictions
77// 3. Using Firebase App Check for additional security
88
9+ // =============================================================================
10+ // ENVIRONMENT CONFIGURATION
11+ // =============================================================================
12+ // Set to 'development' for local testing with dummy data
13+ // Set to 'production' for live app with real data
14+ //
15+ // Option 1: Use URL parameter: ?env=development
16+ // Option 2: Use localStorage: localStorage.setItem('appEnv', 'development')
17+ // Option 3: Automatic: localhost = development, otherwise = production
18+ // =============================================================================
19+
20+ // Check environment from multiple sources
21+ const getEnvironment = ( ) => {
22+ // 1. Check URL parameter (highest priority for quick testing)
23+ const urlParams = new URLSearchParams ( window . location . search ) ;
24+ if ( urlParams . get ( 'env' ) ) return urlParams . get ( 'env' ) ;
25+
26+ // 2. Check localStorage (persists across sessions)
27+ if ( localStorage . getItem ( 'appEnv' ) ) return localStorage . getItem ( 'appEnv' ) ;
28+
29+ // 3. Check if running on localhost
30+ if ( window . location . hostname === 'localhost' || window . location . hostname === '127.0.0.1' ) {
31+ return 'development' ;
32+ }
33+
34+ // 4. Default to production
35+ return 'production' ;
36+ } ;
37+
38+ const APP_ENV = getEnvironment ( ) ;
39+
40+ // Collection prefix based on environment
41+ // Production: 'items', 'purchases', etc.
42+ // Development: 'dev_items', 'dev_purchases', etc.
43+ const COLLECTION_PREFIX = APP_ENV === 'production' ? '' : 'dev_' ;
44+
45+ // Collections that should NOT be prefixed (shared between dev and prod)
46+ // - users: Keep same user roles/permissions in dev
47+ const SHARED_COLLECTIONS = [ 'users' ] ;
48+
49+ console . log ( `🔧 App Environment: ${ APP_ENV } | Collection Prefix: "${ COLLECTION_PREFIX } "` ) ;
50+
51+ // Single Firebase Config (same project for both environments)
952const firebaseConfig = {
1053 apiKey : "AIzaSyD0ib9JkKbqaNE2i_TZlXYJqEtXI_i2Fj8" ,
1154 authDomain : "aadhat-management.firebaseapp.com" ,
@@ -16,6 +59,43 @@ const firebaseConfig = {
1659 measurementId : "G-01155M3XPL"
1760} ;
1861
62+ // Expose environment globally
63+ window . APP_ENV = APP_ENV ;
64+ window . COLLECTION_PREFIX = COLLECTION_PREFIX ;
65+
66+ // Helper function to get prefixed collection name
67+ // Some collections are shared (not prefixed) between dev and prod
68+ window . getCollection = ( name ) => {
69+ if ( SHARED_COLLECTIONS . includes ( name ) ) {
70+ return name ; // No prefix for shared collections
71+ }
72+ return COLLECTION_PREFIX + name ;
73+ } ;
74+
75+ // Show environment indicator in UI (for development only)
76+ if ( APP_ENV !== 'production' ) {
77+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
78+ const indicator = document . createElement ( 'div' ) ;
79+ indicator . id = 'env-indicator' ;
80+ indicator . innerHTML = `🔧 ${ APP_ENV . toUpperCase ( ) } ` ;
81+ indicator . style . cssText = `
82+ position: fixed;
83+ top: 0;
84+ left: 50%;
85+ transform: translateX(-50%);
86+ background: #ff6b35;
87+ color: white;
88+ padding: 2px 12px;
89+ font-size: 10px;
90+ font-weight: bold;
91+ z-index: 99999;
92+ border-radius: 0 0 4px 4px;
93+ text-transform: uppercase;
94+ ` ;
95+ document . body . appendChild ( indicator ) ;
96+ } ) ;
97+ }
98+
1999// Initialize Firebase
20100let app ;
21101try {
0 commit comments