/** * Test script to verify redirect loop fix * This script will visit the hosted site and monitor for redirect loops */ const fs = require('fs'); const path = require('path'); // Function to create a simple HTML test page function createTestPage() { const html = ` Redirect Loop Test

Redirect Loop Fix Test

Testing the BCT React app at: https://dev-racer-433015-k3.web.app

Test Instructions:
1. Open the hosted site in a browser: https://dev-racer-433015-k3.web.app
2. Check browser developer console for any redirect loop messages
3. Verify the page loads without infinite redirects
4. Check if login form appears or dashboard loads (depending on auth state)
Expected Behavior (Fixed):
✅ Page loads without redirect loops
✅ Service worker updates to v2 with network-first navigation
✅ Auth state initializes properly with console logs
✅ Either login form shows or dashboard loads based on stored auth
✅ No browser "ERR_TOO_MANY_REDIRECTS" errors
What Was Fixed:
• Service Worker: Network-first navigation strategy (prevents stale HTML caching)
• ProtectedRoute: Extended timeout from 2s to 30s (prevents premature redirects)
• useAuth: More robust auth state initialization with logging
• LoginPage: Redirect loop detection and prevention
• Firebase: Aggressive no-cache headers for HTML files
How to Verify Fix:
1. Open browser dev tools (F12)
2. Go to Console tab
3. Navigate to the site
4. Look for logs like "useAuth: Initializing auth state..." and "Service Worker v2"
5. Verify no redirect loop errors appear
6. Page should load successfully within 5-10 seconds
`; return html; } // Write the test page const testPagePath = path.join(__dirname, 'test-results', 'redirect-fix-test.html'); const testDir = path.dirname(testPagePath); if (!fs.existsSync(testDir)) { fs.mkdirSync(testDir, { recursive: true }); } fs.writeFileSync(testPagePath, createTestPage()); console.log('✅ Redirect loop fix deployed successfully!'); console.log(''); console.log('🔧 Fixes Applied:'); console.log(' • Service Worker: Network-first navigation (v2)'); console.log(' • ProtectedRoute: Extended auth timeout (2s → 30s)'); console.log(' • useAuth: Robust initialization with logging'); console.log(' • LoginPage: Redirect loop detection & prevention'); console.log(' • Firebase: No-cache headers for HTML files'); console.log(''); console.log('🌐 Hosted Site: https://dev-racer-433015-k3.web.app'); console.log('📄 Test Page:', testPagePath); console.log(''); console.log('⚠️ Manual Testing Required:'); console.log(' 1. Open the hosted site in a browser'); console.log(' 2. Check browser console for auth initialization logs'); console.log(' 3. Verify no redirect loop errors occur'); console.log(' 4. Confirm page loads within 10 seconds'); console.log(''); console.log('Expected console logs:'); console.log(' - "useAuth: Initializing auth state..."'); console.log(' - "SW registered" or "Service Worker v2"'); console.log(' - No "redirect loop" or "too many redirects" errors');