Skip to content

Commit

Permalink
prettier, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbjoralt committed Oct 13, 2023
1 parent abb0ff6 commit ac53614
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion frontend/src/app/bemanning/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fetchWithToken } from "@/data/fetchWithToken";
import { Variant } from "@/types";

export default async function Bemanning() {
const consultants = await fetchWithToken<Variant[]>("variants") ?? [];
const consultants = (await fetchWithToken<Variant[]>("variants")) ?? [];

return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/DepartmentFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fetchWithToken } from "@/data/fetchWithToken";
import { Department } from "@/types";

export default async function DepartmentFilter() {
const departments = await fetchWithToken<Department[]>("departments")?? [];
const departments = (await fetchWithToken<Department[]>("departments")) ?? [];

if (departments.length > 0) {
return (
Expand Down
13 changes: 6 additions & 7 deletions frontend/src/data/fetchWithToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import {
getCustomServerSession,
} from "@/app/api/auth/[...nextauth]/route";

export async function fetchWithToken<T>(path: string): Promise<T | undefined> {
export async function fetchWithToken<T>(path: string): Promise<T | undefined> {
if (process.env.NEXT_PUBLIC_NO_AUTH) {
return mockedCall<T>(path);
}

const session = await getCustomServerSession(authOptions);

if(!session || !session.access_token) return;

if (!session || !session.access_token) return;

const apiBackendUrl =
process.env.NEXT_PUBLIC_VIBES_BACKEND_URL ?? "http://localhost:7172/v0";
Expand All @@ -30,16 +29,16 @@ export async function fetchWithToken<T>(path: string): Promise<T | undefined> {
};

const response = await fetch(`${apiBackendUrl}/${path}`, options);
return await response.json() as T;
return (await response.json()) as T;
}

function mockedCall<T>(path: string): Promise<T> {
return new Promise((resolve) => {
return new Promise((resolve) => {
if (path.includes("variants")) {
resolve(MockConsultants as T);
}
if (path.includes("departments")) {
resolve(MockDepartments as T);
resolve(MockDepartments as T);
}
})
});
}
7 changes: 5 additions & 2 deletions frontend/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { withAuth } from "next-auth/middleware";
export default withAuth({
callbacks: {
authorized: ({ req, token }) => {
return !!token && !req.nextUrl.basePath.startsWith("/login");
return (
(!!token && !req.nextUrl.basePath.startsWith("/login")) ||
!!process.env.NEXT_PUBLIC_NO_AUTH
);
},
},
});
});

0 comments on commit ac53614

Please sign in to comment.