diff --git a/client/src/App.tsx b/client/src/App.tsx
index 9fffd7c..3fc08f7 100644
--- a/client/src/App.tsx
+++ b/client/src/App.tsx
@@ -1,10 +1,10 @@
-import { Switch, Route } from "wouter";
+import { Switch, Route, Redirect } from "wouter";
import { queryClient } from "./lib/queryClient";
import { QueryClientProvider } from "@tanstack/react-query";
import { Toaster } from "@/components/ui/toaster";
import { TooltipProvider } from "@/components/ui/tooltip";
import { FloatingVoiceControl } from "@/components/voice/FloatingVoiceControl";
-import { AuthProvider } from "@/context/AuthContext";
+import { AuthProvider, useAuth } from "@/context/AuthContext";
import { ThemeProvider } from "@/context/ThemeContext";
import { AdaptiveThemeProvider } from "@/context/AdaptiveThemeContext";
import { VoiceProvider } from "@/context/VoiceProvider";
@@ -12,6 +12,7 @@ import { NotificationProvider } from "@/context/NotificationProvider";
import { TourManagerProvider } from "@/components/onboarding/TourManager";
import { MoodDetector } from "@/components/MoodDetector";
import { RTLProvider } from "@/components/RTLProvider";
+import { Skeleton } from "@/components/ui/skeleton";
import LandingPage from "@/pages/LandingPage";
import DashboardPage from "@/pages/DashboardPage";
import LoginPage from "@/pages/LoginPage";
@@ -31,26 +32,81 @@ import ChatPage from "@/pages/ChatPage";
import ComfortHubPage from "@/pages/ComfortHubPage";
import NotFound from "@/pages/not-found";
+// Protected Route wrapper
+function ProtectedRoute({ component: Component }: { component: React.ComponentType }) {
+ const { user, isLoading } = useAuth();
+
+ if (isLoading) {
+ return (
+
+ );
+ }
+
+ if (!user) {
+ return ;
+ }
+
+ // Check if user needs onboarding
+ if (!user.onboardingComplete) {
+ return ;
+ }
+
+ return ;
+}
+
+// Public route that redirects authenticated users
+function PublicRoute({ component: Component }: { component: React.ComponentType }) {
+ const { user, isLoading } = useAuth();
+
+ if (isLoading) {
+ return (
+
+ );
+ }
+
+ if (user) {
+ if (!user.onboardingComplete) {
+ return ;
+ }
+ return ;
+ }
+
+ return ;
+}
+
function Router() {
return (
-
-
-
+ } />
+ } />
+ } />
-
-
-
-
-
-
-
-
-
-
-
-
-
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
);
diff --git a/client/src/pages/AIPage.tsx b/client/src/pages/AIPage.tsx
index 1da7931..aac7928 100644
--- a/client/src/pages/AIPage.tsx
+++ b/client/src/pages/AIPage.tsx
@@ -38,14 +38,12 @@ export default function AIPage() {
setIsLoading(true);
try {
- const response = await apiRequest("/api/ai/chat", {
- method: "POST",
- body: JSON.stringify({ message }),
- });
+ const response = await apiRequest("POST", "/api/ai/chat", { message });
+ const data = await response.json();
const aiMessage = {
role: "assistant",
- content: response.content || "I'm here to help! How can I assist you today?",
+ content: data.content || "I'm here to help! How can I assist you today?",
timestamp: new Date()
};
setChatHistory(prev => [...prev, aiMessage]);
diff --git a/client/src/pages/TasksPage.tsx b/client/src/pages/TasksPage.tsx
index 5b29b95..f583901 100644
--- a/client/src/pages/TasksPage.tsx
+++ b/client/src/pages/TasksPage.tsx
@@ -48,7 +48,7 @@ export default function TasksPage() {
// Filter and sort tasks
const filteredAndSortedTasks = useMemo(() => {
- if (!tasks) return [];
+ if (!Array.isArray(tasks)) return [];
const filtered = tasks.filter((task: any) => {
const matchesSearch = task.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
@@ -68,9 +68,9 @@ export default function TasksPage() {
bValue = b.title.toLowerCase();
break;
case "priority":
- const priorityOrder = { high: 3, medium: 2, low: 1 };
- aValue = priorityOrder[a.priority] || 0;
- bValue = priorityOrder[b.priority] || 0;
+ const priorityOrder: Record = { high: 3, medium: 2, low: 1 };
+ aValue = priorityOrder[a.priority as string] || 0;
+ bValue = priorityOrder[b.priority as string] || 0;
break;
case "dueDate":
aValue = a.dueDate ? new Date(a.dueDate) : new Date('9999-12-31');