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