diff --git a/FIREBASE_SETUP.md b/FIREBASE_SETUP.md new file mode 100644 index 0000000..18939de --- /dev/null +++ b/FIREBASE_SETUP.md @@ -0,0 +1,65 @@ +# Firebase Authentication Setup + +This application uses Firebase Authentication for user management. Follow these steps to configure Firebase: + +## 1. Create a Firebase Project + +1. Go to [Firebase Console](https://console.firebase.google.com/) +2. Click "Create a project" or "Add project" +3. Enter your project name (e.g., "aviation-sales-report") +4. Follow the setup wizard + +## 2. Enable Authentication + +1. In your Firebase project, go to "Authentication" in the left sidebar +2. Click "Get started" +3. Go to the "Sign-in method" tab +4. Enable "Email/Password" authentication method + +## 3. Get Your Firebase Configuration + +1. Go to Project Settings (gear icon in the left sidebar) +2. Scroll down to "Your apps" section +3. Click "Add app" and select the web icon (>) +4. Register your app with a nickname +5. Copy the Firebase configuration object + +## 4. Configure Environment Variables + +Create a `.env.local` file in the root directory and add your Firebase configuration: + +```env +NEXT_PUBLIC_FIREBASE_API_KEY=your-api-key +NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com +NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id +NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project.appspot.com +NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789 +NEXT_PUBLIC_FIREBASE_APP_ID=your-app-id +``` + +Replace the values with your actual Firebase configuration values. + +## 5. Test the Authentication + +1. Run the development server: `npm run dev` +2. Navigate to `/login` +3. Try creating a new account with the "Sign Up" tab +4. Try signing in with existing credentials +5. Test the logout functionality from the dashboard + +## Security Notes + +- Never commit your `.env.local` file to version control +- The `.env.local` file is already included in `.gitignore` +- All Firebase configuration values starting with `NEXT_PUBLIC_` are safe to expose in the browser +- Make sure to configure Firebase security rules for production use + +## Features Included + +- ✅ Email/Password authentication +- ✅ User registration (Sign Up) +- ✅ User login (Sign In) +- ✅ User logout +- ✅ Protected routes (dashboard redirects to login if not authenticated) +- ✅ Loading states and error handling +- ✅ Responsive design with dark mode support diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index b4263af..e95ebc0 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -2,52 +2,70 @@ import Link from "next/link"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { faPlus, faSearch } from "@fortawesome/free-solid-svg-icons"; +import { faPlus, faSearch, faSignOutAlt } from "@fortawesome/free-solid-svg-icons"; import FlightBriefLogo from "@/components/FlightBriefLogo"; -import { useState } from "react"; +import { useState, useEffect } from "react"; +import { useAuth } from "@/contexts/AuthContext"; +import { useRouter } from "next/navigation"; -// Example reports data -const exampleReports = [ - { - id: 1, - name: "Q3 Flight Operations Summary", - date: "2025-09-10", - type: "Operations Report" - }, - { - id: 2, - name: "Aircraft Maintenance Analysis", - date: "2025-09-08", - type: "Maintenance Report" - }, - { - id: 3, - name: "Safety Incident Review - August", - date: "2025-09-01", - type: "Safety Report" - }, - { - id: 4, - name: "Fleet Utilization Metrics", - date: "2025-08-28", - type: "Performance Report" - }, - { - id: 5, - name: "Fuel Cost Analysis - Summer 2025", - date: "2025-08-25", - type: "Financial Report" - }, - { - id: 6, - name: "Pilot Training Progress Update", - date: "2025-08-20", - type: "Training Report" - } -]; +// Reports data - will be fetched from database +const exampleReports: any[] = []; export default function Dashboard() { const [searchQuery, setSearchQuery] = useState(""); + const { user, logout } = useAuth(); + const router = useRouter(); + + + // Filter reports based on search query + const filteredReports = exampleReports.filter(report => { + if (!searchQuery.trim()) return true; + + const query = searchQuery.toLowerCase(); + return ( + report.name.toLowerCase().includes(query) || + report.type.toLowerCase().includes(query) + ); + }); + + // Function to highlight search terms + const highlightText = (text: string, query: string) => { + if (!query.trim()) return text; + + const regex = new RegExp(`(${query})`, 'gi'); + const parts = text.split(regex); + + return parts.map((part, index) => + regex.test(part) ? ( + + {part} + + ) : part + ); + }; + + useEffect(() => { + if (!user) { + router.push("/login"); + } + }, [user, router]); + + const handleLogout = async () => { + try { + await logout(); + router.push("/login"); + } catch (error) { + console.error("Failed to log out", error); + } + }; + + if (!user) { + return ( +
- Here are your recent flight reports and analytics + Manage your aviation reports and analytics
- {report.type} -
-- {new Date(report.date).toLocaleDateString('en-US', { - month: 'short', - day: 'numeric', - year: 'numeric' - })} -
-+ {searchQuery.trim() ? `No reports found for "${searchQuery}"` : "No reports available"} +
++ Create your first report to get started +
+ {highlightText(report.type, searchQuery)} +
++ {new Date(report.date).toLocaleDateString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric' + })} +
+