|
| 1 | +# Firebase Setup Guide for Ensori |
| 2 | + |
| 3 | +This guide will help you set up Firebase for your Ensori todo app to enable user authentication and data persistence. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- A Google account |
| 8 | +- Node.js and npm installed |
| 9 | +- The Ensori project cloned and dependencies installed |
| 10 | + |
| 11 | +## Step 1: Create a Firebase Project |
| 12 | + |
| 13 | +1. Go to the [Firebase Console](https://console.firebase.google.com/) |
| 14 | +2. Click "Create a project" or "Add project" |
| 15 | +3. Enter your project name (e.g., "ensori-todo-app") |
| 16 | +4. Choose whether to enable Google Analytics (optional but recommended) |
| 17 | +5. Click "Create project" |
| 18 | + |
| 19 | +## Step 2: Set Up Authentication |
| 20 | + |
| 21 | +1. In your Firebase project console, click on "Authentication" in the left sidebar |
| 22 | +2. Click "Get started" |
| 23 | +3. Go to the "Sign-in method" tab |
| 24 | +4. Enable the following sign-in providers: |
| 25 | + - **Email/Password**: Click on it and toggle "Enable" |
| 26 | + - **Google**: Click on it, toggle "Enable", and add your project's domain (e.g., `localhost` for development, your production domain for deployment) |
| 27 | + |
| 28 | +## Step 3: Set Up Firestore Database |
| 29 | + |
| 30 | +1. In your Firebase project console, click on "Firestore Database" in the left sidebar |
| 31 | +2. Click "Create database" |
| 32 | +3. Choose "Start in test mode" (you can configure security rules later) |
| 33 | +4. Select a location for your database (choose the one closest to your users) |
| 34 | + |
| 35 | +## Step 4: Get Your Firebase Configuration |
| 36 | + |
| 37 | +1. In your Firebase project console, click on the gear icon ⚙️ next to "Project Overview" |
| 38 | +2. Select "Project settings" |
| 39 | +3. Scroll down to "Your apps" section |
| 40 | +4. Click on "Web" icon `</>` |
| 41 | +5. Register your app with a nickname (e.g., "Ensori Web App") |
| 42 | +6. Copy the Firebase configuration object |
| 43 | + |
| 44 | +## Step 5: Configure Environment Variables |
| 45 | + |
| 46 | +1. In your Ensori project root, create a file called `.env.local` |
| 47 | +2. Add your Firebase configuration values: |
| 48 | + |
| 49 | +```env |
| 50 | +NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key_here |
| 51 | +NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project_id.firebaseapp.com |
| 52 | +NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id |
| 53 | +NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project_id.appspot.com |
| 54 | +NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_messaging_sender_id |
| 55 | +NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id |
| 56 | +``` |
| 57 | + |
| 58 | +**Important**: Replace all the placeholder values with your actual Firebase configuration values. |
| 59 | + |
| 60 | +## Step 6: Configure Firestore Security Rules (Recommended) |
| 61 | + |
| 62 | +1. Go to "Firestore Database" in your Firebase console |
| 63 | +2. Click on the "Rules" tab |
| 64 | +3. Replace the default rules with the following secure rules: |
| 65 | + |
| 66 | +```javascript |
| 67 | +rules_version = '2'; |
| 68 | +service cloud.firestore { |
| 69 | + match /databases/{database}/documents { |
| 70 | + // Users can only access their own todos |
| 71 | + match /todos/{todoId} { |
| 72 | + allow read, write: if request.auth != null && request.auth.uid == resource.data.userId; |
| 73 | + allow create: if request.auth != null && request.auth.uid == request.resource.data.userId; |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +4. Click "Publish" |
| 80 | + |
| 81 | +## Step 7: Test Your Setup |
| 82 | + |
| 83 | +1. Start your development server: |
| 84 | + |
| 85 | + ```bash |
| 86 | + npm run dev |
| 87 | + ``` |
| 88 | + |
| 89 | +2. Open your browser to `http://localhost:3000` |
| 90 | + |
| 91 | +3. You should see a beautiful landing page with a "Get Started" button |
| 92 | + |
| 93 | +4. Click "Get Started" and try: |
| 94 | + - Creating a new account with email/password |
| 95 | + - Signing in with Google |
| 96 | + - Adding some todo items |
| 97 | + - Logging out and back in to verify data persistence |
| 98 | + |
| 99 | +## Features You Now Have |
| 100 | + |
| 101 | +✅ **User Authentication** |
| 102 | + |
| 103 | +- Email/password sign up and login |
| 104 | +- Google Sign-In |
| 105 | +- Password reset functionality |
| 106 | +- Secure user sessions |
| 107 | + |
| 108 | +✅ **User-Specific Data** |
| 109 | + |
| 110 | +- Each user has their own private todo list |
| 111 | +- Real-time data sync across devices |
| 112 | +- Automatic backup and persistence |
| 113 | + |
| 114 | +✅ **Daily Workflow System** |
| 115 | + |
| 116 | +- Automatic reset of completed tasks at midnight (per user) |
| 117 | +- Preserves ongoing and todo items |
| 118 | +- User-specific daily reset timing |
| 119 | + |
| 120 | +✅ **Security** |
| 121 | + |
| 122 | +- Users can only access their own data |
| 123 | +- Secure authentication |
| 124 | +- Protected API endpoints |
| 125 | + |
| 126 | +## Troubleshooting |
| 127 | + |
| 128 | +### "Firebase: Error (auth/configuration-not-found)" |
| 129 | + |
| 130 | +- Make sure your `.env.local` file is in the project root |
| 131 | +- Verify all environment variables are correctly named with `NEXT_PUBLIC_` prefix |
| 132 | +- Restart your development server after adding environment variables |
| 133 | + |
| 134 | +### "Missing or insufficient permissions" |
| 135 | + |
| 136 | +- Check your Firestore security rules |
| 137 | +- Make sure you're authenticated when trying to access data |
| 138 | +- Verify the user ID matches in your security rules |
| 139 | + |
| 140 | +### Google Sign-In not working |
| 141 | + |
| 142 | +- Make sure you've enabled Google as a sign-in provider in Firebase Authentication |
| 143 | +- Add your domain (localhost for development) to the authorized domains list |
| 144 | + |
| 145 | +## Production Deployment |
| 146 | + |
| 147 | +When deploying to production: |
| 148 | + |
| 149 | +1. Add your production domain to Firebase Authentication authorized domains |
| 150 | +2. Update your `.env.local` with production environment variables |
| 151 | +3. Consider upgrading Firestore to production mode with proper security rules |
| 152 | +4. Set up proper CORS settings if needed |
| 153 | + |
| 154 | +## Next Steps |
| 155 | + |
| 156 | +Your Ensori app now has full user authentication and data persistence! Users can: |
| 157 | + |
| 158 | +- Create accounts and sign in securely |
| 159 | +- Have their own private todo lists |
| 160 | +- Sync data across multiple devices |
| 161 | +- Enjoy the daily workflow system with automatic task reset |
| 162 | + |
| 163 | +The app will automatically handle user sessions, data syncing, and provide a smooth user experience across all devices. |
0 commit comments