diff --git a/app/Admin/layout.tsx b/app/Admin/layout.tsx index 696a445..a59f214 100644 --- a/app/Admin/layout.tsx +++ b/app/Admin/layout.tsx @@ -1,11 +1,13 @@ import React from "react"; -export default function AdminLayout({children}: {children: React.ReactNode}) { +import ProtectedRoute from "@/components/wrappers/ProtectedRoute"; + +export default async function AdminLayout({ + children, +}: { + children: React.ReactNode; +}) { // TODO: Put user state management here //redirect("wherever state says") <= stateRouteManager() - return ( -
- {children} -
- ) - } \ No newline at end of file + return {children}; +} diff --git a/app/Admin/page.tsx b/app/Admin/page.tsx index c19c6e1..05169a4 100644 --- a/app/Admin/page.tsx +++ b/app/Admin/page.tsx @@ -1,6 +1,5 @@ -import { redirect } from "next/navigation"; +import UnderConstruction from "@/components/static_pages/UnderConstruction"; export default function Admin() { - // TODO: Replace with Layout State Manager - redirect("/Admin/Login"); + return ; } diff --git a/app/Admin/Login/page.tsx b/app/Authentication/Login/page.tsx similarity index 50% rename from app/Admin/Login/page.tsx rename to app/Authentication/Login/page.tsx index c176301..89264a1 100644 --- a/app/Admin/Login/page.tsx +++ b/app/Authentication/Login/page.tsx @@ -2,12 +2,16 @@ import { useState } from "react"; import { login, signup } from "@/lib/server_functions/userAuth"; +import Form from "@/components/ui/Form"; export default function Login() { const [createAccount, setCreateAccount] = useState(false); return ( -
-
+
+ - - - + +
); } diff --git a/components/ui/Form.tsx b/components/ui/Form.tsx new file mode 100644 index 0000000..7f0e323 --- /dev/null +++ b/components/ui/Form.tsx @@ -0,0 +1,25 @@ +import React from "react"; + +import RoundedContainer from "./RoundedContainer"; + +export default function Form({ + action, + children, + submitText, +}: { + // eslint-disable-next-line no-unused-vars + action?: string | ((formData: FormData) => void | Promise); + children: React.ReactNode; + submitText: string; +}) { + return ( +
+
+ + {children} + + +
+
+ ); +} diff --git a/components/wrappers/ProtectedRoute.tsx b/components/wrappers/ProtectedRoute.tsx new file mode 100644 index 0000000..2c75bbc --- /dev/null +++ b/components/wrappers/ProtectedRoute.tsx @@ -0,0 +1,17 @@ +import React from "react"; +import { redirect } from "next/navigation"; + +import { verifySession } from "@/lib/server_functions/dataAccessLayer"; + +export default async function ProtectedRoute({ + children, +}: { + children: React.ReactNode; +}) { + const session = await verifySession(); + if (!session.isAuthed) { + redirect("/Authentication/Login"); + } + + return
{children}
; +}