From 0cebe2b97e9aa56cfd071a8158191b6e06c48cfc Mon Sep 17 00:00:00 2001
From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com>
Date: Thu, 29 May 2025 22:25:30 -0700
Subject: [PATCH] Changed error boundary to cover both full hub and disaptch
app
---
apps/dispatch/app/_components/Error.tsx | 45 +++++++++++
.../app/_components/ErrorBoundary.tsx | 29 +++++++
apps/dispatch/app/_components/map/Map.tsx | 1 -
.../app/api/auth/[...nextauth]/auth.ts | 18 ++++-
apps/dispatch/app/dispatch/layout.tsx | 4 +
apps/dispatch/app/layout.tsx | 7 +-
apps/dispatch/app/pilot/layout.tsx | 4 +
apps/dispatch/package.json | 1 +
.../mail-templates/PasswordChanged.tsx | 21 ++---
apps/hub/app/(app)/_components/Events.tsx | 9 +--
apps/hub/app/(app)/_components/Stats.tsx | 32 +++-----
apps/hub/app/(app)/admin/event/layout.tsx | 12 ++-
apps/hub/app/(app)/admin/keyword/layout.tsx | 13 ++-
apps/hub/app/(app)/admin/report/layout.tsx | 13 +--
apps/hub/app/(app)/admin/station/layout.tsx | 13 ++-
.../admin/user/[id]/_components/forms.tsx | 81 ++++---------------
apps/hub/app/(app)/admin/user/layout.tsx | 13 ++-
apps/hub/app/(app)/events/page.tsx | 6 +-
apps/hub/app/(auth)/layout.tsx | 36 ++-------
apps/hub/app/_components/ErrorBoundary.tsx | 29 +++++++
apps/hub/app/api/auth/[...nextauth]/auth.ts | 22 ++++-
apps/hub/app/layout.tsx | 3 +-
apps/hub/helper/authServices.ts | 2 +-
pnpm-lock.yaml | 6 ++
24 files changed, 226 insertions(+), 194 deletions(-)
create mode 100644 apps/dispatch/app/_components/Error.tsx
create mode 100644 apps/dispatch/app/_components/ErrorBoundary.tsx
create mode 100644 apps/hub/app/_components/ErrorBoundary.tsx
diff --git a/apps/dispatch/app/_components/Error.tsx b/apps/dispatch/app/_components/Error.tsx
new file mode 100644
index 00000000..8386b58a
--- /dev/null
+++ b/apps/dispatch/app/_components/Error.tsx
@@ -0,0 +1,45 @@
+"use client";
+
+import { useEffect } from "react";
+
+export const Error = ({ statusCode, title }: { statusCode: number; title: string }) => {
+ return (
+
+
+
{statusCode}
+
Oh nein! Ein Fehler ist aufgetreten.
+
{title || "Ein unerwarteter Fehler ist aufgetreten."}
+
+
+
+ );
+};
+
+export const ErrorFallback = ({
+ error,
+ reset,
+}: {
+ error: Error & { digest?: string };
+ reset: () => void;
+}) => {
+ useEffect(() => {
+ // Log the error to an error reporting service
+ console.error(error);
+ }, [error]);
+
+ return (
+
+
Something went wrong!
+
+
+ );
+};
diff --git a/apps/dispatch/app/_components/ErrorBoundary.tsx b/apps/dispatch/app/_components/ErrorBoundary.tsx
new file mode 100644
index 00000000..3b60d886
--- /dev/null
+++ b/apps/dispatch/app/_components/ErrorBoundary.tsx
@@ -0,0 +1,29 @@
+"use client";
+
+import { ErrorBoundary } from "react-error-boundary";
+import { Error as ErrorComp } from "./Error";
+
+export const CustomErrorBoundary = ({ children }: { children?: React.ReactNode }) => {
+ return (
+ {
+ console.log(error);
+ let errorTest;
+ let errorCode = 500;
+ if ("statusCode" in error) {
+ errorCode = (error as any).statusCode;
+ }
+ if ("message" in error || error instanceof Error) {
+ errorTest = (error as any).message;
+ } else if (typeof error === "string") {
+ errorTest = error;
+ } else {
+ errorTest = "Ein unerwarteter Fehler ist aufgetreten.";
+ }
+ return ;
+ }}
+ >
+ {children}
+
+ );
+};
diff --git a/apps/dispatch/app/_components/map/Map.tsx b/apps/dispatch/app/_components/map/Map.tsx
index c26558eb..331adcc8 100644
--- a/apps/dispatch/app/_components/map/Map.tsx
+++ b/apps/dispatch/app/_components/map/Map.tsx
@@ -14,7 +14,6 @@ import { Map as TMap } from "leaflet";
const Map = () => {
const ref = useRef(null);
const { map, setMap } = useMapStore();
-
useEffect(() => {
// Sync map zoom and center with the map store
if (ref.current) {
diff --git a/apps/dispatch/app/api/auth/[...nextauth]/auth.ts b/apps/dispatch/app/api/auth/[...nextauth]/auth.ts
index f296c17c..ef02c74a 100644
--- a/apps/dispatch/app/api/auth/[...nextauth]/auth.ts
+++ b/apps/dispatch/app/api/auth/[...nextauth]/auth.ts
@@ -70,9 +70,25 @@ export const options: AuthOptions = {
return token;
},
session: async ({ session, user, token }) => {
+ const dbUser = await prisma.user.findUnique({
+ where: {
+ id: token?.sub,
+ },
+ });
+ if (!dbUser) {
+ return {
+ ...session,
+ user: {
+ name: null,
+ email: null,
+ image: null,
+ },
+ expires: new Date().toISOString(),
+ };
+ }
return {
...session,
- user: token,
+ user: dbUser,
};
},
},
diff --git a/apps/dispatch/app/dispatch/layout.tsx b/apps/dispatch/app/dispatch/layout.tsx
index 98865f30..b8c72619 100644
--- a/apps/dispatch/app/dispatch/layout.tsx
+++ b/apps/dispatch/app/dispatch/layout.tsx
@@ -2,6 +2,7 @@ import type { Metadata } from "next";
import Navbar from "./_components/navbar/Navbar";
import { redirect } from "next/navigation";
import { getServerSession } from "../api/auth/[...nextauth]/auth";
+import { Error } from "_components/Error";
export const metadata: Metadata = {
title: "VAR v2: Disponent",
@@ -14,9 +15,12 @@ export default async function RootLayout({
children: React.ReactNode;
}>) {
const session = await getServerSession();
+
if (!session) {
redirect("/login");
}
+ if (!session.user.permissions.includes("DISPO"))
+ return ;
return (
<>
diff --git a/apps/dispatch/app/layout.tsx b/apps/dispatch/app/layout.tsx
index 06104868..2a5062e2 100644
--- a/apps/dispatch/app/layout.tsx
+++ b/apps/dispatch/app/layout.tsx
@@ -5,6 +5,9 @@ import { NextAuthSessionProvider } from "./_components/AuthSessionProvider";
import { getServerSession } from "./api/auth/[...nextauth]/auth";
import { Toaster } from "react-hot-toast";
import { QueryProvider } from "_components/QueryProvider";
+import { Error as ErrorComp } from "_components/Error";
+import { ErrorBoundary } from "react-error-boundary";
+import { CustomErrorBoundary } from "_components/ErrorBoundary";
const geistSans = localFont({
src: "./fonts/GeistVF.woff",
@@ -47,9 +50,7 @@ export default async function RootLayout({
reverseOrder={false}
/>
-
- {children}
-
+ {children}