summaryrefslogtreecommitdiff
path: root/src2/components/auth/WithAuth.js
blob: ef975873d8c5ad44f890ee166377b6d1b5fb6f49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;