diff --git a/backend/pkg/router/login.go b/backend/pkg/router/login.go
index c68215c..333f9cc 100644
--- a/backend/pkg/router/login.go
+++ b/backend/pkg/router/login.go
@@ -8,8 +8,7 @@ import (
)
type UserLogin struct {
- UserID int `json:"userID"`
- Name string `json:"name"`
+ UserName string `json:"userName"`
LoggedIn bool `json:"loggedIn"`
}
@@ -48,8 +47,7 @@ func handleWelcome(c *fiber.Ctx) error {
user := users[0]
response.Data = UserLogin{
- UserID: user.UserID,
- Name: user.Name,
+ UserName: user.UserName,
LoggedIn: true,
}
}
diff --git a/backend/pkg/router/router.go b/backend/pkg/router/router.go
index bd83802..673f26d 100644
--- a/backend/pkg/router/router.go
+++ b/backend/pkg/router/router.go
@@ -164,8 +164,7 @@ func extractJWT(c *fiber.Ctx) (int, string, error) {
// user-entry in the database
type UserDB struct {
- UserID int `json:"userID"`
- Name string `json:"name"`
+ UserName string `json:"userName"`
Password []byte `json:"password"`
Admin bool `json:"admin"`
TokenID string `json:"tokenID"`
@@ -216,6 +215,6 @@ func checkAdmin(c *fiber.Ctx) (bool, error) {
if len(response) != 1 {
return false, fmt.Errorf("user doesn't exist")
} else {
- return response[0].Name == "admin" && response[0].TokenID == tokenID, err
+ return response[0].UserName == "admin" && response[0].TokenID == tokenID, err
}
}
diff --git a/client/package-lock.json b/client/package-lock.json
index b0f1dc9..0baf46a 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -21,6 +21,7 @@
"@nextui-org/modal": "^2.2.7",
"@nextui-org/radio": "^2.3.8",
"@nextui-org/select": "^2.4.9",
+ "@nextui-org/spinner": "^2.2.6",
"@nextui-org/switch": "^2.2.8",
"@nextui-org/system": "^2.4.6",
"@nextui-org/table": "^2.2.8",
diff --git a/client/package.json b/client/package.json
index 8ceeb72..8777850 100644
--- a/client/package.json
+++ b/client/package.json
@@ -22,6 +22,7 @@
"@nextui-org/modal": "^2.2.7",
"@nextui-org/radio": "^2.3.8",
"@nextui-org/select": "^2.4.9",
+ "@nextui-org/spinner": "^2.2.6",
"@nextui-org/switch": "^2.2.8",
"@nextui-org/system": "^2.4.6",
"@nextui-org/table": "^2.2.8",
diff --git a/client/src/app/Header.tsx b/client/src/app/Header.tsx
new file mode 100644
index 0000000..8f12c8f
--- /dev/null
+++ b/client/src/app/Header.tsx
@@ -0,0 +1,11 @@
+import { Link } from "@nextui-org/link";
+
+export default function Header() {
+ return (
+
+
+
Volunteer Scheduler
+
+
+ );
+}
diff --git a/client/src/app/Main.tsx b/client/src/app/Main.tsx
new file mode 100644
index 0000000..49a73ca
--- /dev/null
+++ b/client/src/app/Main.tsx
@@ -0,0 +1,55 @@
+"use client";
+
+import { apiCall } from "@/lib";
+import { Spinner } from "@nextui-org/spinner";
+import { usePathname, useRouter } from "next/navigation";
+import React, { useEffect, useState } from "react";
+
+enum AuthState {
+ Loading,
+ LoginScreen,
+ Unauthorized,
+ LoggedIn,
+}
+
+export default function Main({ children }: { children: React.ReactNode }) {
+ const [status, setStatus] = useState(AuthState.Loading);
+
+ const router = useRouter();
+ const pathname = usePathname();
+
+ useEffect(() => {
+ void (async () => {
+ if (pathname === "/login") {
+ setStatus(AuthState.LoginScreen);
+ } else {
+ const welcomeResult = await apiCall<{
+ userName: string;
+ loggedIn: boolean;
+ }>("GET", "welcome");
+
+ if (!welcomeResult.ok) {
+ router.push("/login");
+ } else {
+ const response = await welcomeResult.json();
+
+ if (response.loggedIn) {
+ setStatus(AuthState.LoggedIn);
+ } else {
+ setStatus(AuthState.Unauthorized);
+ }
+ }
+ }
+ })();
+ });
+
+ switch (status) {
+ case AuthState.Loading:
+ return ;
+ case AuthState.LoggedIn:
+ case AuthState.LoginScreen:
+ return children;
+ case AuthState.Unauthorized:
+ return "";
+ }
+}
diff --git a/client/src/app/layout.tsx b/client/src/app/layout.tsx
index e027c9d..d6e1ce5 100644
--- a/client/src/app/layout.tsx
+++ b/client/src/app/layout.tsx
@@ -3,6 +3,8 @@ import "./globals.css";
import { NextUIProvider } from "@nextui-org/system";
import React from "react";
import Footer from "./Footer";
+import Header from "./Header";
+import Main from "./Main";
export const metadata: Metadata = {
title: "Create Next App",
@@ -31,11 +33,11 @@ export default function RootLayout({
-
- Volunteer Scheduler
-
+
-
{children}
+
+ {children}
+
diff --git a/client/src/app/login/page.tsx b/client/src/app/login/page.tsx
new file mode 100644
index 0000000..3022b3e
--- /dev/null
+++ b/client/src/app/login/page.tsx
@@ -0,0 +1,53 @@
+"use client";
+
+import { ViewFilled, ViewOffFilled } from "@carbon/icons-react";
+import { Button } from "@nextui-org/button";
+import { Form } from "@nextui-org/form";
+import { Input } from "@nextui-org/input";
+import { Switch } from "@nextui-org/switch";
+import { useState } from "react";
+
+export default function Login() {
+ const [visibility, setVisibility] = useState(false);
+
+ return (
+
+
Login
+
+
+ );
+}
diff --git a/client/src/app/page.tsx b/client/src/app/page.tsx
index 43edf4f..2ebe897 100644
--- a/client/src/app/page.tsx
+++ b/client/src/app/page.tsx
@@ -1,54 +1,6 @@
-"use client";
-
-import { Input } from "@nextui-org/input";
-import { useState } from "react";
-import { ViewFilled, ViewOffFilled } from "@carbon/icons-react";
-import { Switch } from "@nextui-org/switch";
-import { Button } from "@nextui-org/button";
-import { Form } from "@nextui-org/form";
+import OverviewPersonal from "./me/page";
export default function Home() {
- const [visibility, setVisibility] = useState(false);
-
// return
;
- return (
-
-
Login
-
-
- );
+ return
;
}