diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-27 10:49:45 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-27 10:49:45 +0700 |
| commit | ffa261e6adef70a2845878cf93e6e492eb8cee62 (patch) | |
| tree | c860ac8d127795ee813af59923305736596264c2 /src/lib/auth/components/IsAuth.jsx | |
| parent | 14ad96a9d010790fe7a482035d6d88f36db660fe (diff) | |
footer
Diffstat (limited to 'src/lib/auth/components/IsAuth.jsx')
| -rw-r--r-- | src/lib/auth/components/IsAuth.jsx | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/auth/components/IsAuth.jsx b/src/lib/auth/components/IsAuth.jsx new file mode 100644 index 00000000..1cfd3172 --- /dev/null +++ b/src/lib/auth/components/IsAuth.jsx @@ -0,0 +1,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.replace('/login') + } else { + setResponse(children) + } + }, [children, router]) + + return response +} + +export default IsAuth |
