mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-01 18:20:28 +00:00
Add protected route component
This commit is contained in:
@@ -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<RouteProps> = ({ children, ...rest }) => {
|
||||
const token = useReactiveVar(tokenVar);
|
||||
|
||||
return (
|
||||
<Route
|
||||
{...rest}
|
||||
render={() => (token ? children : <Redirect to='/login' />)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default ProtectedRoute;
|
||||
Reference in New Issue
Block a user