mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-01 18:20:28 +00:00
Add auth route component
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
import { useReactiveVar } from '@apollo/client';
|
||||||
|
import { Redirect, Route, RouteProps } from 'react-router-dom';
|
||||||
|
import { tokenVar } from '../../graphql/state';
|
||||||
|
|
||||||
|
const AuthRoute: React.FC<RouteProps> = ({ children, ...rest }) => {
|
||||||
|
const token = useReactiveVar(tokenVar);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Route {...rest} render={() => (!token ? children : <Redirect to='/' />)} />
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AuthRoute;
|
||||||
Reference in New Issue
Block a user