From e345488763167043e759a5df67a29d47cb6a1bad Mon Sep 17 00:00:00 2001 From: andrei Date: Sat, 5 Oct 2024 10:19:20 +0500 Subject: [PATCH] ._. --- src/AuthContext.jsx | 8 ++++++++ src/components/PrivateRoute.jsx | 4 ++++ src/pages/Home.jsx | 6 +++++- 3 files changed, 17 insertions(+), 1 deletion(-) 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