WIP: Major Update 0.2 #3

Draft
Hannah wants to merge 19 commits from Devbranch into main
5 changed files with 65 additions and 17 deletions
Showing only changes of commit efa42a53b2 - Show all commits

Updated login page, added ProtectedRoute object for wrapping in layouts, added ProtectedRoute authorization verification to Admin route root

Hannah dagemark 2026-09-14 23:12:12 +02:00

View file

@ -1,11 +1,13 @@
import React from "react"; 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 // TODO: Put user state management here
//redirect("wherever state says") <= stateRouteManager() //redirect("wherever state says") <= stateRouteManager()
return ( return <ProtectedRoute>{children}</ProtectedRoute>;
<div> }
{children}
</div>
)
}

View file

@ -1,6 +1,5 @@
import { redirect } from "next/navigation"; import UnderConstruction from "@/components/static_pages/UnderConstruction";
export default function Admin() { export default function Admin() {
// TODO: Replace with Layout State Manager return <UnderConstruction />;
redirect("/Admin/Login");
} }

View file

@ -2,12 +2,16 @@
import { useState } from "react"; import { useState } from "react";
import { login, signup } from "@/lib/server_functions/userAuth"; import { login, signup } from "@/lib/server_functions/userAuth";
import Form from "@/components/ui/Form";
export default function Login() { export default function Login() {
const [createAccount, setCreateAccount] = useState(false); const [createAccount, setCreateAccount] = useState(false);
return ( return (
<div> <div className="flex h-full w-full justify-center py-10">
<form action={createAccount ? login : signup}> <Form
action={createAccount ? login : signup}
submitText={createAccount ? "Login" : "Signup"}
>
<input type="text" name="username" placeholder="Username" required /> <input type="text" name="username" placeholder="Username" required />
<input <input
type="password" type="password"
@ -15,11 +19,12 @@ export default function Login() {
placeholder="Password" placeholder="Password"
required required
/> />
<button type="submit">{createAccount ? "Login" : "Signup"}</button>
</form>
<button onClick={() => setCreateAccount(!createAccount)}> <button onClick={() => setCreateAccount(!createAccount)}>
{createAccount ? "Don't have an account?" : "Already have an account?"} {createAccount
? "Don't have an account?"
: "Already have an account?"}
</button> </button>
</Form>
</div> </div>
); );
} }

25
components/ui/Form.tsx Normal file
View file

@ -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<void>);
children: React.ReactNode;
submitText: string;
}) {
return (
<div>
<form action={action}>
<RoundedContainer slim={false}>
{children}
<button type="submit">{submitText}</button>
</RoundedContainer>
</form>
</div>
);
}

View file

@ -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 <div>{children}</div>;
}