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