summaryrefslogtreecommitdiff
path: root/src/lib/auth/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/auth/components')
-rw-r--r--src/lib/auth/components/IsAuth.jsx20
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