Created
August 8, 2022 11:51
-
-
Save zinedkaloc/0d366c5c8d0927a265eb3565113eba7e to your computer and use it in GitHub Desktop.
This file contains 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 from 'react'; | |
import { useLocation, Navigate } from 'react-router-dom'; | |
import { useAuth } from '../contexts/Auth'; | |
export function PrivateRoute({ children }) { | |
const { session } = useAuth(); | |
let location = useLocation(); | |
return session ? ( | |
children | |
) : ( | |
<Navigate to="/login" state={{ from: location }} replace /> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment