From 99977d5f56a377e9eca6a448de9af027e4dd921f Mon Sep 17 00:00:00 2001 From: ghaddaditw <40211818-ghaddaditw@users.noreply.replit.com> Date: Fri, 30 May 2025 17:11:54 +0000 Subject: [PATCH] Enable user authentication and authorization throughout the application Refactors authentication logic into AuthContext and removes useAuth hook. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 556aa286-edd2-4cea-8583-f4fc3cfd119b --- client/src/context/AuthContext.tsx | 2 ++ client/src/hooks/useAuth.ts | 11 +---------- client/src/pages/LandingPage.tsx | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/client/src/context/AuthContext.tsx b/client/src/context/AuthContext.tsx index c74baa2..18c7948 100644 --- a/client/src/context/AuthContext.tsx +++ b/client/src/context/AuthContext.tsx @@ -14,6 +14,8 @@ interface AuthContextType { const AuthContext = createContext(undefined); +export { AuthContext }; + export function AuthProvider({ children }: { children: React.ReactNode }) { const [user, setUser] = useState(null); const [isLoading, setIsLoading] = useState(true); diff --git a/client/src/hooks/useAuth.ts b/client/src/hooks/useAuth.ts index b6ff8d4..a7ddc85 100644 --- a/client/src/hooks/useAuth.ts +++ b/client/src/hooks/useAuth.ts @@ -1,10 +1 @@ -import { useContext } from "react"; -import { AuthContext } from "@/context/AuthContext"; - -export function useAuth() { - const context = useContext(AuthContext); - if (context === undefined) { - throw new Error("useAuth must be used within an AuthProvider"); - } - return context; -} +export { useAuth } from "@/context/AuthContext"; diff --git a/client/src/pages/LandingPage.tsx b/client/src/pages/LandingPage.tsx index abbb8bf..accf71a 100644 --- a/client/src/pages/LandingPage.tsx +++ b/client/src/pages/LandingPage.tsx @@ -25,7 +25,7 @@ import { export default function LandingPage() { const [, setLocation] = useLocation(); - const { user } = useAuth() || {}; + const { user } = useAuth(); const { isListening, startListening, stopListening, isSupported } = useVoice(); const { theme } = useTheme();