App directory #4
This commit is contained in:
parent
69706053c6
commit
4d743c5e67
86 changed files with 223 additions and 107 deletions
22
apps/metamigo-frontend/app/_components/Auth.tsx
Normal file
22
apps/metamigo-frontend/app/_components/Auth.tsx
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
"use client";
|
||||
|
||||
import { FC, PropsWithChildren, useEffect } from "react";
|
||||
import { CircularProgress } from "@mui/material";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export const Auth: FC<PropsWithChildren> = ({ children }) => {
|
||||
const router = useRouter();
|
||||
const { data: session, status: loading } = useSession();
|
||||
useEffect(() => {
|
||||
if (!session && !loading) {
|
||||
router.push("/login");
|
||||
}
|
||||
}, [session, loading, router]);
|
||||
|
||||
if (loading) {
|
||||
return <CircularProgress />;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue