From e6e41765212ca2b892814fada948f745a7bad7f0 Mon Sep 17 00:00:00 2001 From: Jaya Surya Date: Fri, 11 Aug 2023 20:47:01 +0530 Subject: [PATCH 01/40] some minor changes --- app/protectedLayouts.tsx | 45 +++++++------ components/AppBar/AppBar.tsx | 4 +- components/AppBar/AppBarAdmin.tsx | 107 ++++++++++++++++++++++++++++++ pages/_app.tsx | 2 +- pages/admin.tsx | 11 +-- pages/admin/events.tsx | 0 pages/admin/home.tsx | 16 ----- pages/admin/members.tsx | 0 pages/admin/project.tsx | 0 pages/admin/register.tsx | 0 10 files changed, 140 insertions(+), 45 deletions(-) create mode 100644 components/AppBar/AppBarAdmin.tsx create mode 100644 pages/admin/events.tsx delete mode 100644 pages/admin/home.tsx create mode 100644 pages/admin/members.tsx create mode 100644 pages/admin/project.tsx create mode 100644 pages/admin/register.tsx diff --git a/app/protectedLayouts.tsx b/app/protectedLayouts.tsx index 7266004..0b73773 100644 --- a/app/protectedLayouts.tsx +++ b/app/protectedLayouts.tsx @@ -1,22 +1,21 @@ -// components/layouts/protectedLayouts.tsx - import { useSession } from 'next-auth/react' import { useRouter } from 'next/router' import { useEffect } from 'react' - -type Props = { - children: React.ReactElement +import AppBarAdmin from './../components/AppBar/AppBarAdmin' +import Footer from '@/components/Footer/Footer' +import './globals.css' +import AppBar from '@/components/AppBar/AppBar' +import './globals.css' +import { Inter } from 'next/font/google' +import { ReactNode } from 'react' +import { NextAuthProvider } from './../pages/provider' + +interface RootLayoutProps { + // Use interface for prop types + children: ReactNode } -/* - add the requireAuth property to the page component - to protect the page from unauthenticated users - e.g.: - OrderDetail.requireAuth = true; - export default OrderDetail; - */ - -const ProtectedLayout = ({ children }: Props): JSX.Element => { +function ProtectedLayout({ children }: RootLayoutProps) { const router = useRouter() const { status: sessionStatus } = useSession() const authorized = sessionStatus === 'authenticated' @@ -24,11 +23,8 @@ const ProtectedLayout = ({ children }: Props): JSX.Element => { const loading = sessionStatus === 'loading' useEffect(() => { - // check if the session is loading or the router is not ready if (loading || !router.isReady) return - // if the user is not authorized, redirect to the login page - // with a return url to the current page if (unAuthorized) { console.log('not authorized') router.push({ @@ -37,14 +33,19 @@ const ProtectedLayout = ({ children }: Props): JSX.Element => { } }, [loading, unAuthorized, sessionStatus, router]) - // if the user refreshed the page or somehow navigated to the protected page if (loading) { - return <>Loading app... + return <>Loading app... //need to change to loading screen } - // if the user is authorized, render the page - // otherwise, render nothing while the router redirects him to the login page - return authorized ?
{children}
: <> + return authorized ? ( + <> + +
{children}
+