summaryrefslogtreecommitdiff
path: root/src/components/auth/WithAuth.js
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-01-24 15:54:48 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-01-24 15:54:48 +0700
commitee4297280c1305c7e03bedd4df63ccf136c28c6c (patch)
tree62eb00777f42542a37c63687dd1536f8f56df894 /src/components/auth/WithAuth.js
parent23b31aa10302cc990f3fb083b8189233b2e9e08d (diff)
Merapihkan struktur folder
Diffstat (limited to 'src/components/auth/WithAuth.js')
-rw-r--r--src/components/auth/WithAuth.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/components/auth/WithAuth.js b/src/components/auth/WithAuth.js
new file mode 100644
index 00000000..ef975873
--- /dev/null
+++ b/src/components/auth/WithAuth.js
@@ -0,0 +1,20 @@
+import { getAuth } from "@/core/utils/auth";
+import { useRouter } from "next/router";
+import { useEffect, useState } from "react";
+
+const WithAuth = ({ children }) => {
+ const router = useRouter();
+ const [response, setResponse] = useState(<></>);
+
+ useEffect(() => {
+ if (!getAuth()) {
+ router.replace('/login');
+ } else {
+ setResponse(children);
+ }
+ }, [children, router]);
+
+ return response;
+}
+
+export default WithAuth; \ No newline at end of file