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
This commit is contained in:
@@ -14,6 +14,8 @@ interface AuthContextType {
|
|||||||
|
|
||||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||||
|
|
||||||
|
export { AuthContext };
|
||||||
|
|
||||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||||
const [user, setUser] = useState<User | null>(null);
|
const [user, setUser] = useState<User | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|||||||
@@ -1,10 +1 @@
|
|||||||
import { useContext } from "react";
|
export { useAuth } from "@/context/AuthContext";
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import {
|
|||||||
|
|
||||||
export default function LandingPage() {
|
export default function LandingPage() {
|
||||||
const [, setLocation] = useLocation();
|
const [, setLocation] = useLocation();
|
||||||
const { user } = useAuth() || {};
|
const { user } = useAuth();
|
||||||
const { isListening, startListening, stopListening, isSupported } = useVoice();
|
const { isListening, startListening, stopListening, isSupported } = useVoice();
|
||||||
const { theme } = useTheme();
|
const { theme } = useTheme();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user