import {FC, ReactNode} from 'react';
import {LOGIN_PATH} from '@routes';
import {useStore} from 'zustand';
import {userStore} from '@stores';

const Auth: FC<{children: ReactNode}> = function ({children}) {
  const token = useStore(userStore, state => state.token);

  if (!token) {
    parent ? parent.location.replace(LOGIN_PATH) : location.replace(LOGIN_PATH);
    return null;
  }

  return <>{children}</>;
};

export default Auth;
