From ed2ebe41e69dccd10d37098f3b82affb5bfbc9f7 Mon Sep 17 00:00:00 2001 From: Chief Bube Date: Fri, 20 Oct 2023 17:18:36 -0700 Subject: [PATCH] completed middleware --- middleware.js | 2 +- middlewares/AuthRoute.js | 11 ++++++----- pages/_app.js | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/middleware.js b/middleware.js index a373b1c..ae34892 100644 --- a/middleware.js +++ b/middleware.js @@ -22,7 +22,7 @@ export async function middleware(req) { } if (authenticationPages.includes(pathname) && !authenticated) { - return NextResponse.redirect(new URL("/auth/", origin)); + return NextResponse.redirect(new URL("/auth/login", origin)); } return NextResponse.next(); diff --git a/middlewares/AuthRoute.js b/middlewares/AuthRoute.js index ba915d9..29beaf6 100644 --- a/middlewares/AuthRoute.js +++ b/middlewares/AuthRoute.js @@ -10,12 +10,13 @@ import { useRouter } from "next/router"; const AuthRoute = ({ children }) => { const router = useRouter(); - const isAuthenticated = false; // In a real application, this would be determined based on the user's authentication status. + useEffect(() => { + const isAuthenticated = false; // In a real application, this would be determined based on the user's authentication status. - if (!isAuthenticated) { - router.push("/"); - return null; - } + if (!isAuthenticated) { + router.push("/"); + } + }, []); return <>{children}; }; diff --git a/pages/_app.js b/pages/_app.js index feaebbe..d21f59a 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -23,11 +23,11 @@ function MyApp({ Component, pageProps }) { <> - + {/* */} - + {/* */} );