import { PropsWithChildren, useEffect } from 'react'
import { useNavigate } from 'react-router-dom'

import { getToken } from '../utils/auth'

function WithToken({ children }: PropsWithChildren) {
    const navigate = useNavigate()

    useEffect(() => {
        if (!getToken()) {
            return navigate('/login')
        }
    }, [navigate])

    return (
        <>{children}</>
    )
}

export default WithToken
