import {FC, ReactNode} from 'react';
import {Navigate} from 'react-router-dom';
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);

  return (
    <>
      {token.length ? children : <Navigate replace to={LOGIN_PATH} />}
    </>
  );
};

export default Auth;
