2022-05-28 17:32:35 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Redirect, Route, RouteProps } from 'react-router';
|
|
|
|
import { useStoreState } from '@/state/hooks';
|
|
|
|
|
|
|
|
export default ({ children, ...props }: Omit<RouteProps, 'render'>) => {
|
2022-06-26 19:13:52 +00:00
|
|
|
const isAuthenticated = useStoreState((state) => !!state.user.data?.uuid);
|
2022-05-28 17:32:35 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Route
|
|
|
|
{...props}
|
2022-06-26 19:13:52 +00:00
|
|
|
render={({ location }) =>
|
|
|
|
isAuthenticated ? children : <Redirect to={{ pathname: '/auth/login', state: { from: location } }} />
|
|
|
|
}
|
2022-05-28 17:32:35 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|