2023-03-14 17:40:24 +00:00
|
|
|
import { FC, useEffect } from "react";
|
2023-02-13 12:41:30 +00:00
|
|
|
import { CircularProgress } from "@material-ui/core";
|
|
|
|
|
import { useSession } from "next-auth/react";
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
2023-03-14 17:40:24 +00:00
|
|
|
export const Auth: FC = ({ children }) => {
|
2023-02-13 12:41:30 +00:00
|
|
|
const router = useRouter();
|
|
|
|
|
const { data: session, status: loading } = useSession();
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!session && !loading) {
|
|
|
|
|
router.push("/login");
|
|
|
|
|
}
|
|
|
|
|
}, [session, loading]);
|
|
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
return <CircularProgress />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <>{children}</>;
|
|
|
|
|
};
|