summaryrefslogtreecommitdiff
path: root/src/lib/auth/components/IsAuth.jsx
blob: a32e648cda6151101c654caed5453a50a5b08584 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import { getAuth } from '@/core/utils/auth'

const IsAuth = ({ children }) => {
  const router = useRouter()
  const [response, setResponse] = useState(<></>)

  useEffect(() => {
    if (!getAuth() && router.pathname != '/login') {
      router.replace(`/login?next=${router.asPath}`)
    } else {
      setResponse(children)
    }
  }, [children, router])

  return response
}

export default IsAuth