Created
October 6, 2024 11:57
-
-
Save paulweezydesign/28fbc7d11431f19e80a1ab8dd46298f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useContext } from 'react'; | |
import { AuthContext } from './AuthProvider'; | |
import { Navigate } from 'react-router-dom'; | |
const ProtectedRoute = ({ children }) => { | |
const { user, loading } = useContext(AuthContext); | |
if (loading) { | |
return <div>Loading...</div>; | |
} | |
if (!user) { | |
return <Navigate to="/login" replace />; | |
} | |
return children; | |
}; | |
export default ProtectedRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment