diff --git a/backend/Api/Departments/DeparmentController.cs b/backend/Api/Departments/DeparmentController.cs index 91c99176..76405de6 100644 --- a/backend/Api/Departments/DeparmentController.cs +++ b/backend/Api/Departments/DeparmentController.cs @@ -1,7 +1,7 @@ using Database.DatabaseContext; using Microsoft.AspNetCore.Mvc; -[Route("/departments")] +[Route("/v0/departments")] [ApiController] public class DepartmentController : ControllerBase { diff --git a/frontend/src/app/bemanning/page.tsx b/frontend/src/app/bemanning/page.tsx index 3ddcd66c..b502c7ee 100644 --- a/frontend/src/app/bemanning/page.tsx +++ b/frontend/src/app/bemanning/page.tsx @@ -1,8 +1,9 @@ import FilteredConsultantsList from "@/components/FilteredConsultantsList"; -import { getConsultants } from "@/data/getConsultants"; +import { fetchWithToken } from "@/data/fetchWithToken"; +import { Variant } from "@/types"; export default async function Bemanning() { - const consultants = await getConsultants(); + const consultants = await fetchWithToken("variants") ?? []; return (
diff --git a/frontend/src/components/DepartmentFilter.tsx b/frontend/src/components/DepartmentFilter.tsx index edd59a28..a2a08b25 100644 --- a/frontend/src/components/DepartmentFilter.tsx +++ b/frontend/src/components/DepartmentFilter.tsx @@ -1,8 +1,9 @@ import FilterButton from "./FilterButton"; -import getDepartment from "@/data/getDepartment"; +import { fetchWithToken } from "@/data/fetchWithToken"; +import { Department } from "@/types"; export default async function DepartmentFilter() { - const departments = await getDepartment(); + const departments = await fetchWithToken("departments")?? []; if (departments.length > 0) { return ( diff --git a/frontend/src/components/SignInField.tsx b/frontend/src/components/SignInField.tsx deleted file mode 100644 index 65c928f7..00000000 --- a/frontend/src/components/SignInField.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import { Box } from "@mui/material"; -import SignInButton from "./vibes-buttons/SignInButton"; - -function SignInField() { - return ( - - Sign in with Azure Entra ID - - ); -} - -export default SignInField; diff --git a/frontend/src/data/fetchWithToken.ts b/frontend/src/data/fetchWithToken.ts index 795a7bf2..ab520130 100644 --- a/frontend/src/data/fetchWithToken.ts +++ b/frontend/src/data/fetchWithToken.ts @@ -5,13 +5,16 @@ import { getCustomServerSession, } from "@/app/api/auth/[...nextauth]/route"; -export async function fetchWithToken(path: string) { +export async function fetchWithToken(path: string): Promise { if (process.env.NEXT_PUBLIC_NO_AUTH) { - return mockedCall(path); + return mockedCall(path); } const session = await getCustomServerSession(authOptions); + if(!session || !session.access_token) return; + + const apiBackendUrl = process.env.NEXT_PUBLIC_VIBES_BACKEND_URL ?? "http://localhost:7172/v0"; @@ -26,19 +29,17 @@ export async function fetchWithToken(path: string) { headers: headers, }; - try { - const response = await fetch(`${apiBackendUrl}/${path}`, options); - return await response.json(); - } catch (error) { - console.error(error); - } + const response = await fetch(`${apiBackendUrl}/${path}`, options); + return await response.json() as T; } -function mockedCall(path: string) { - if (path.includes("variants")) { - return MockConsultants; - } - if (path.includes("departments")) { - return MockDepartments; - } +function mockedCall(path: string): Promise { + return new Promise((resolve) => { + if (path.includes("variants")) { + resolve(MockConsultants as T); + } + if (path.includes("departments")) { + resolve(MockDepartments as T); + } + }) } diff --git a/frontend/src/data/getConsultants.ts b/frontend/src/data/getConsultants.ts deleted file mode 100644 index 4130a7d0..00000000 --- a/frontend/src/data/getConsultants.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { fetchWithToken } from "@/data/fetchWithToken"; -import { Variant } from "@/types"; - -export async function getConsultants() { - return (await fetchWithToken("variants")) as Variant[]; -} diff --git a/frontend/src/data/getDepartment.ts b/frontend/src/data/getDepartment.ts deleted file mode 100644 index 36c4b6d9..00000000 --- a/frontend/src/data/getDepartment.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { fetchWithToken } from "@/data/fetchWithToken"; -import { Department } from "@/types"; - -export default async function getDepartment() { - return (await fetchWithToken("departments")) as Department[]; -} diff --git a/frontend/src/middleware.ts b/frontend/src/middleware.ts new file mode 100644 index 00000000..1d4f6157 --- /dev/null +++ b/frontend/src/middleware.ts @@ -0,0 +1,9 @@ +import { withAuth } from "next-auth/middleware"; + +export default withAuth({ + callbacks: { + authorized: ({ req, token }) => { + return !!token && !req.nextUrl.basePath.startsWith("/login"); + }, + }, +}); \ No newline at end of file