From 6245f236cb75422a291ff0eae9792ed475bdb0fd Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Wed, 28 Apr 2021 21:26:29 +0100 Subject: [PATCH] Add protected route component --- src/components/ProtectedRoute/index.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/components/ProtectedRoute/index.tsx diff --git a/src/components/ProtectedRoute/index.tsx b/src/components/ProtectedRoute/index.tsx new file mode 100644 index 0000000..9c709e9 --- /dev/null +++ b/src/components/ProtectedRoute/index.tsx @@ -0,0 +1,16 @@ +import { useReactiveVar } from '@apollo/client'; +import { Redirect, Route, RouteProps } from 'react-router-dom'; +import { tokenVar } from '../../graphql/state'; + +const ProtectedRoute: React.FC = ({ children, ...rest }) => { + const token = useReactiveVar(tokenVar); + + return ( + (token ? children : )} + /> + ); +}; + +export default ProtectedRoute;