From d62f02b1dfd485df9966277ab5e60001d8ccec3e Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 17 Apr 2025 13:35:10 +0200 Subject: [PATCH] database wf 12 --- app/page.tsx | 19 +++++++++++++++++++ middleware.ts | 26 ++++++++++++++------------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index d97c64a1..2bf7c383 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -6,8 +6,27 @@ import { News } from "@/components/news"; import { Duties } from "@/components/flow"; import { Email } from "@/components/email"; import { Parole } from "@/components/parole"; +import { useSession } from "next-auth/react"; +import { useEffect, useState } from "react"; export default function Home() { + const { data: session, status } = useSession(); + const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + if (status !== "loading") { + setIsLoading(false); + } + }, [status]); + + if (isLoading) { + return ( +
+
+
+ ); + } + return (
diff --git a/middleware.ts b/middleware.ts index 42e19583..4c34f904 100644 --- a/middleware.ts +++ b/middleware.ts @@ -3,18 +3,6 @@ import { NextResponse } from "next/server"; export default withAuth( function middleware(req) { - // Allow access to public paths - if ( - req.nextUrl.pathname === "/" || - req.nextUrl.pathname === "/signin" || - req.nextUrl.pathname.startsWith("/_next") || - req.nextUrl.pathname.startsWith("/api/auth") || - req.nextUrl.pathname.startsWith("/public") - ) { - return NextResponse.next(); - } - - // For all other routes, check authentication return NextResponse.next(); }, { @@ -31,6 +19,20 @@ export default withAuth( return true; } + // For API routes, check if the request is for mail or other protected endpoints + if (req.nextUrl.pathname.startsWith('/api/')) { + // Allow access to public API endpoints + if ( + req.nextUrl.pathname.startsWith('/api/auth') || + req.nextUrl.pathname.startsWith('/api/news') + ) { + return true; + } + + // Require authentication for protected API endpoints + return !!token; + } + // For all other routes, require a valid token return !!token; },