2022-05-05 13:42:18 +02:00
|
|
|
import { IRoute } from 'interfaces/route';
|
|
|
|
import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
|
|
|
|
import { LoginRedirect } from 'component/common/LoginRedirect/LoginRedirect';
|
2022-05-02 12:52:33 +02:00
|
|
|
|
|
|
|
interface IProtectedRouteProps {
|
2022-05-05 13:42:18 +02:00
|
|
|
route: IRoute;
|
2022-05-02 12:52:33 +02:00
|
|
|
}
|
|
|
|
|
2022-05-05 13:42:18 +02:00
|
|
|
export const ProtectedRoute = ({ route }: IProtectedRouteProps) => {
|
|
|
|
const { user } = useAuthUser();
|
|
|
|
const isLoggedIn = Boolean(user?.id);
|
2022-05-02 12:52:33 +02:00
|
|
|
|
2022-05-05 13:42:18 +02:00
|
|
|
if (!isLoggedIn && route.type === 'protected') {
|
|
|
|
return <LoginRedirect />;
|
|
|
|
}
|
2022-05-02 12:52:33 +02:00
|
|
|
|
2022-05-05 13:42:18 +02:00
|
|
|
return <route.component />;
|
|
|
|
};
|