Skip to content

Commit

Permalink
update protectedRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-torabiv committed Sep 1, 2024
1 parent 08b9687 commit cc347c2
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@ const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
const { isConnected } = useAccount();

useEffect(() => {
if (!isConnected) {
setIsAuthenticated(false);
localStorage.removeItem('OCI_TOKEN');
}
}, [isConnected]);

useEffect(() => {
const checkAuthStatus = async () => {
const token = localStorage.getItem('OCI_TOKEN');
if (token) {
setIsAuthenticated(true);
const checkAuthStatus = () => {
if (isConnected) {
const token = localStorage.getItem('OCI_TOKEN');
setIsAuthenticated(!!token);
} else {
setIsAuthenticated(false);
localStorage.removeItem('OCI_TOKEN');
}
setLoading(false);
};

checkAuthStatus();
}, []);
}, [isConnected]);

if (loading) {
return (
Expand Down

0 comments on commit cc347c2

Please sign in to comment.