diff --git a/src/AuthContext.jsx b/src/AuthContext.jsx index ac996e2..dacd1d0 100644 --- a/src/AuthContext.jsx +++ b/src/AuthContext.jsx @@ -1,3 +1,11 @@ +import React, { createContext, useContext, useState, useEffect } from 'react'; + +const AuthContext = createContext(); + +export const useAuth = () => { + return useContext(AuthContext); +}; + export const AuthProvider = ({ children }) => { const [isAuthenticated, setIsAuthenticated] = useState(() => { const savedAuth = localStorage.getItem('isAuthenticated'); diff --git a/src/components/PrivateRoute.jsx b/src/components/PrivateRoute.jsx index 0b45d13..96e0150 100644 --- a/src/components/PrivateRoute.jsx +++ b/src/components/PrivateRoute.jsx @@ -5,6 +5,10 @@ import { useAuth } from '../AuthContext.jsx'; const PrivateRoute = () => { const { isAuthenticated } = useAuth(); + if (isAuthenticated === null) { + return
Loading...
; + } + return isAuthenticated ? : ; }; diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx index d5a8b4a..3ece38a 100644 --- a/src/pages/Home.jsx +++ b/src/pages/Home.jsx @@ -2,5 +2,9 @@ import React, { useState, useEffect } from 'react'; const Home = () => { - return + return ( +
+ sadvsgrhgrtshte +
+ ) } \ No newline at end of file