From 92c451efe5032ee308fccfb53eaed2f6d9d98d68 Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 21 Feb 2025 14:10:21 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20v=C3=A9rification=20d'authentif?= =?UTF-8?q?ication=20dans=20le=20layout=20principal,=20mise=20=C3=A0=20jou?= =?UTF-8?q?r=20des=20m=C3=A9tadonn=C3=A9es=20des=20pages=20et=20cr=C3=A9at?= =?UTF-8?q?ion=20d'un=20nouveau=20composant=20LoginCard=20pour=20la=20conn?= =?UTF-8?q?exion=20avec=20Keycloak.=20Mise=20=C3=A0=20jour=20du=20fichier?= =?UTF-8?q?=20.gitignore=20pour=20inclure=20les=20playbooks=20de=20d=C3=A9?= =?UTF-8?q?veloppement.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +- front/app/layout.tsx | 69 ++++++++++++++------- front/app/page.tsx | 5 +- front/app/signin/page.tsx | 90 +++------------------------- front/components/auth/login-card.tsx | 32 ++++++++++ 5 files changed, 95 insertions(+), 106 deletions(-) create mode 100644 front/components/auth/login-card.tsx diff --git a/.gitignore b/.gitignore index d8d6005..7861025 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,7 @@ node_modules # Scripts de développement copy.sh -start.sh \ No newline at end of file +start.sh + +# Playbook développement +ansible/playbooks/dev \ No newline at end of file diff --git a/front/app/layout.tsx b/front/app/layout.tsx index 14224b8..a3c5417 100644 --- a/front/app/layout.tsx +++ b/front/app/layout.tsx @@ -6,9 +6,34 @@ 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
Chargement...
; + } + + if (status === "unauthenticated" && pathname !== "/signin") { + return null; + } + + return <>{children}; +} + interface RootLayoutProps { children: React.ReactNode; } @@ -17,29 +42,31 @@ export default function RootLayout({ children, }: Readonly): JSX.Element { return ( - + -
- -
{children}
-
-
- - Support - - - Help Center - - - Privacy - - - Terms of Service - -
-
-
+ +
+ +
{children}
+
+
+ + Support + + + Centre d'aide + + + Confidentialité + + + Conditions d'utilisation + +
+
+
+
diff --git a/front/app/page.tsx b/front/app/page.tsx index 58ea8b3..7e396f2 100644 --- a/front/app/page.tsx +++ b/front/app/page.tsx @@ -6,10 +6,13 @@ import { CalendarWidget } from "@/components/calendar-widget"; import { News } from "@/components/news"; import { Todo } from "@/components/todo"; +export const metadata = { + title: "Enkun - Dashboard", +}; + export default function Page() { return (
-
diff --git a/front/app/signin/page.tsx b/front/app/signin/page.tsx index 05d851a..54345bd 100644 --- a/front/app/signin/page.tsx +++ b/front/app/signin/page.tsx @@ -1,90 +1,14 @@ -"use client"; +import { Metadata } from "next"; +import { LoginCard } from "@/components/auth/login-card"; -import { useState } from "react"; -import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; -import { - Card, - CardContent, - CardDescription, - CardFooter, - CardHeader, - CardTitle, -} from "@/components/ui/card"; -import { FaGoogle } from "react-icons/fa"; +export const metadata: Metadata = { + title: "Enkun - Connexion", +}; export default function SignInPage() { - const [email, setEmail] = useState(""); - const [password, setPassword] = useState(""); - - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); - // Handle sign-in logic here - console.log("Sign in attempted with:", email, password); - }; - return ( -
- - - Sign In - - Enter your credentials to access your account - - - -
-
- - setEmail(e.target.value)} - required - /> -
-
- - setPassword(e.target.value)} - required - /> -
- -
-
- -
-
- -
-
- - Or continue with - -
-
-
- - -
-
-
+
+
); } diff --git a/front/components/auth/login-card.tsx b/front/components/auth/login-card.tsx new file mode 100644 index 0000000..f0e723d --- /dev/null +++ b/front/components/auth/login-card.tsx @@ -0,0 +1,32 @@ +"use client"; + +import { signIn } from "next-auth/react"; +import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; + +export function LoginCard() { + return ( + + + Bienvenue sur Enkun + + Connectez-vous pour accéder à votre espace + + + + + + + ); +}