Neah-Enkun/front/app/layout.tsx

75 lines
2.2 KiB
TypeScript

"use client";
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import { MainNav } from "@/components/main-nav";
import Link from "next/link";
import { SessionProvider } from "next-auth/react";
import { useSession } from "next-auth/react";
import { usePathname, useRouter } from "next/navigation";
import { useEffect } from "react";
const inter = Inter({ subsets: ["latin"] });
function AuthCheck({ children }: { children: React.ReactNode }) {
const { data: session, status } = useSession();
const pathname = usePathname();
const router = useRouter();
useEffect(() => {
if (status === "unauthenticated" && pathname !== "/signin") {
router.push("/signin");
}
}, [status, router, pathname]);
if (status === "loading") {
return <div>Chargement...</div>;
}
if (status === "unauthenticated" && pathname !== "/signin") {
return null;
}
return <>{children}</>;
}
interface RootLayoutProps {
children: React.ReactNode;
}
export default function RootLayout({
children,
}: Readonly<RootLayoutProps>): JSX.Element {
return (
<html lang='fr'>
<body className={`${inter.className} bg-background text-foreground`}>
<SessionProvider>
<AuthCheck>
<div className='min-h-screen flex flex-col'>
<MainNav />
<main className='flex-1'>{children}</main>
<footer className='w-full p-4 bg-black text-white/80'>
<div className='flex space-x-4 text-sm'>
<Link href='/support' className='hover:text-white'>
Support
</Link>
<Link href='/help' className='hover:text-white'>
Centre d'aide
</Link>
<Link href='/privacy' className='hover:text-white'>
Confidentialité
</Link>
<Link href='/tos' className='hover:text-white'>
Conditions d'utilisation
</Link>
</div>
</footer>
</div>
</AuthCheck>
</SessionProvider>
</body>
</html>
);
}