import { useNavigate } from 'react-router-dom'
import { AuthService } from '../authService.ts'
import { useEffect } from 'react'
import { useUser } from '../../user/user.ts'

interface LogoutPageProps {
  authService: AuthService
}

export default function LogoutPage({ authService }: LogoutPageProps) {
  const navigate = useNavigate()
  const user = useUser()

  useEffect(() => {
    console.debug(user)
    if (!user) {
      navigate('/login')
    }
  }, [user, navigate])

  useEffect(() => {
    const timeout = setTimeout(() => authService.logout())
    return () => clearTimeout(timeout)
  }, [authService])

  return <></>
}
