'use client'

// React Imports
import { useEffect } from 'react'

// Next Imports
import { usePathname, useRouter } from 'next/navigation'

// Config Imports
import themeConfig from '@configs/themeConfig'

const AuthRedirect = () => {
  const pathname = usePathname()
  const router = useRouter()

  useEffect(() => {
    const login = '/login'
    const homePage = themeConfig.homePageUrl
    const redirectUrl =
      pathname === login ? login : pathname === homePage ? login : `/login?redirectTo=${pathname}`
    router.replace(redirectUrl)
  }, [pathname, router])

  return null
}

export default AuthRedirect
