Successfully migrated Dashboard.tsx from REST API (localhost:5000) to Firebase backend services.
// Added Firebase imports
import { useFirebaseAuth } from "@/integrations/firebase/useFirebaseAuth";
import { getUserProjects, getUser } from "@/integrations/firebase/firebaseService";
// Removed REST API constant
// const API_BASE = "http://localhost:5000";- Added
useFirebaseAuth()hook to get current authenticated user - Replaced REST API authentication (buildwave_token) with Firebase Authentication
- Updated user profile fetch to use
getUser(userId)from firebaseService - Updated projects fetch to use
getUserProjects(userId)from firebaseService
Before:
const token = localStorage.getItem("buildwave_token");
const res = await fetch(`${API_BASE}/api/projects`, {
headers: { Authorization: `Bearer ${token}` }
});After:
if (!authUser) throw new Error("User not authenticated");
const userProfile = await getUser(authUser.uid);
const userProjects = await getUserProjects(authUser.uid);Before:
const handleLogout = () => {
localStorage.removeItem("buildwave_token");
navigate("/");
};After:
const handleLogout = async () => {
try {
await logout(); // Firebase logout
localStorage.removeItem("buildwave_uid");
localStorage.removeItem("buildwave_user");
localStorage.removeItem("buildwave_email");
navigate("/");
} catch (err) {
console.error("Logout error:", err);
}
};- Removed REST API-specific fields (level, discipline, lastUpdate)
- Updated to use Firebase project structure (category, description, createdAt)
- Added
formatDate()function to properly format Firebase Timestamp objects - Improved date display logic with relative time format (today, yesterday, N days ago, etc.)
- Added description field to project card display
useEffect(() => {
if (!authUser && !loading) {
navigate("/");
}
}, [authUser, navigate, loading]);{
id: string; // Document ID
title: string;
description: string;
status: string; // "In Progress", "Under Review", "Completed", "On Hold", "Pending Review"
userId: string;
category: string; // Instead of: level, discipline
progress?: number; // 0-100
createdAt: Timestamp; // Firebase Timestamp
updatedAt: Timestamp;
// ... other fields
}{
id: string; // Document ID (UID)
name: string;
email: string;
school?: string;
// ... other fields
}- User authenticates via AuthModal
- User redirected to Dashboard after signup
- Dashboard loads user profile correctly
- Dashboard loads user's projects correctly
- Empty state displays when no projects exist
- Project cards display correctly with all fields
- Can click project to view details
- Logout button works and clears localStorage
- Can log back in and see same projects
Other components still using REST API:
- ProjectRequestModal.tsx - Use
createProject()from firebaseService - TrackProjectModal.tsx - Use
getProject()from firebaseService - Admin.tsx - Use admin functions from firebaseService (already done in AdminUsers.tsx)
- AdminLogin.tsx - Migrate to useFirebaseAuth
- AdminProjectDetail.tsx - Use project functions from firebaseService
- TrackProject.tsx - Use
getProject()from firebaseService - useAuth.tsx - Replace with useFirebaseAuth