# Development Mode Authentication ## The Issue When running in development mode (`npm run dev`), authentication attempts were failing with "Unable to connect to server" because the backend API wasn't running. ## The Fix ✅ All authentication methods now work in **development mode with mock data**: ### What Works Now (Without Backend) #### 1. **Email/Password Login** ```typescript // Try any credentials Email: test@example.com Password: anything // Creates a mock user automatically // Shows in console: "🔧 Development mode: Using mock Cognito authentication" ``` #### 2. **Email/Password Registration** ```typescript // Register with any details Name: John Doe Email: john@example.com Password: password123 // Creates a mock user and logs you in ``` #### 3. **Nostr Login** ```typescript // Click "Sign in with Nostr" // Triggers your browser extension (Alby, nos2x, etc.) // Creates a mock Nostr user // Shows in console: "🔧 Development mode: Using mock Nostr authentication" ``` ### What You'll See **After Mock Login:** - ✅ Your name/initials appear in the header - ✅ Profile dropdown works - ✅ Can navigate to Profile & Library pages - ✅ "Sign In" button disappears - ✅ Content becomes accessible - ✅ Subscription/rental modals work ### Mock User Data **Cognito Mock:** ```javascript { id: 'mock-user-test', email: 'test@example.com', legalName: 'Test', // First part of email createdAt: '2026-02-12T...', updatedAt: '2026-02-12T...' } ``` **Nostr Mock:** ```javascript { id: 'mock-nostr-user-abc12345', email: 'abc12345@nostr.local', legalName: 'Nostr User', nostrPubkey: 'abc123...', // Your actual pubkey createdAt: '2026-02-12T...', updatedAt: '2026-02-12T...' } ``` ## Using Real Backend When you're ready to test with the real backend: ### 1. Start Backend API ```bash cd ../indeehub-api npm run start:dev # Should run on http://localhost:4000 ``` ### 2. Configure Frontend ```bash # Edit .env file VITE_USE_MOCK_DATA=false VITE_API_URL=http://localhost:4000 ``` ### 3. Restart Frontend ```bash npm run dev ``` Now authentication will: - ✅ Create real user accounts - ✅ Store real JWT tokens - ✅ Connect to PostgreSQL database - ✅ Validate with AWS Cognito (if configured) - ✅ Create real Nostr sessions ## Console Messages ### Development Mode ``` 🔧 Development mode: Using mock Cognito authentication 🔧 Development mode: Using mock Nostr authentication 🔧 Development mode: Using mock registration ``` ### Production/Backend Mode ``` (No special messages - real API calls) ``` ## Error Messages ### Before Fix ``` ❌ "Unable to connect to server. Please check your internet connection." (Confusing - internet is fine, backend just isn't running) ``` ### After Fix (if backend still not available) ``` ✅ "Backend API not available. To use real authentication, start the backend server and set VITE_USE_MOCK_DATA=false in .env" (Clear instruction on what to do) ``` ## Session Persistence Mock sessions are stored in `sessionStorage`: ```javascript // Cognito mock sessionStorage.setItem('auth_token', 'mock-jwt-token-1234567890') sessionStorage.setItem('refresh_token', 'mock-refresh-token') // Nostr mock sessionStorage.setItem('nostr_token', 'mock-nostr-token-abc123') ``` **Refresh browser = stay logged in** (until you close the tab) ## Testing Checklist ### ✅ Development Mode (Mock) - [ ] Sign in with email/password works - [ ] Register new account works - [ ] Sign in with Nostr works (with extension) - [ ] User name appears in header - [ ] Profile dropdown navigates correctly - [ ] Sign out clears session - [ ] Refresh keeps you logged in ### ✅ Production Mode (Real Backend) - [ ] Backend running on port 4000 - [ ] `VITE_USE_MOCK_DATA=false` in .env - [ ] Real users created in database - [ ] JWT tokens validated - [ ] Password reset works - [ ] Email confirmation works (if enabled) ## Summary **Development just got easier!** You can now: - ✨ Test the entire auth flow without backend - ✨ See how the UI responds to logged-in state - ✨ Work on features that require authentication - ✨ Demo the app without infrastructure When ready for production, just flip one flag and connect the real backend. Everything is already wired up! 🚀