From 1b79472e34c36f24fbb378dedba3817782e545be Mon Sep 17 00:00:00 2001 From: sk1982 Date: Wed, 27 Mar 2024 20:32:39 -0400 Subject: [PATCH] add forbidden and not found pages --- src/app/(centered)/forbidden/page.tsx | 14 ++++++++++++ src/app/not-found.tsx | 13 +++++++++++- src/components/error-page-nav-buttons.tsx | 26 +++++++++++++++++++++++ src/components/login-card.tsx | 7 +++++- src/components/register-card.tsx | 9 ++++++-- src/helpers/permissions.ts | 4 ++-- 6 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 src/app/(centered)/forbidden/page.tsx create mode 100644 src/components/error-page-nav-buttons.tsx diff --git a/src/app/(centered)/forbidden/page.tsx b/src/app/(centered)/forbidden/page.tsx new file mode 100644 index 0000000..072175f --- /dev/null +++ b/src/app/(centered)/forbidden/page.tsx @@ -0,0 +1,14 @@ +import { ErrorPageNavButtons } from '@/components/error-page-nav-buttons'; +import { NoSymbolIcon } from '@heroicons/react/24/outline'; + +export default function ForbiddenPage() { + return (
+ +
+ You do not have permissions to do that. +
+
+ +
+
); +} \ No newline at end of file diff --git a/src/app/not-found.tsx b/src/app/not-found.tsx index 03a661a..5b34743 100644 --- a/src/app/not-found.tsx +++ b/src/app/not-found.tsx @@ -1,3 +1,14 @@ +import { ErrorPageNavButtons } from '@/components/error-page-nav-buttons'; +import { XCircleIcon } from '@heroicons/react/24/outline'; + export default function NotFound() { - return (
Not Found.
) + return (
+ +
+ The link you requested could not be found. +
+
+ +
+
); } diff --git a/src/components/error-page-nav-buttons.tsx b/src/components/error-page-nav-buttons.tsx new file mode 100644 index 0000000..32b33da --- /dev/null +++ b/src/components/error-page-nav-buttons.tsx @@ -0,0 +1,26 @@ +'use client'; + +import { Button } from '@nextui-org/react'; +import Link from 'next/link'; +import { useRouter } from 'next/navigation'; + + +export const ErrorPageNavButtons = () => { + const router = useRouter(); + + return (<> + + + + + + + + ); +}; \ No newline at end of file diff --git a/src/components/login-card.tsx b/src/components/login-card.tsx index 3bfe40e..fec2895 100644 --- a/src/components/login-card.tsx +++ b/src/components/login-card.tsx @@ -20,8 +20,13 @@ export const LoginCard = ({ initialError, referer, callback }: LoginCardProps) = const [error, setError] = useState(initialError ? 'You must be logged in to do that.' : ''); const user = useUser(); - if (user) + if (user) { + if (callback?.startsWith(process.env.NEXT_PUBLIC_BASE_PATH!)) + callback = callback.replace(process.env.NEXT_PUBLIC_BASE_PATH!, ''); + return redirect(callback ?? '/'); + } + const submit = (form: FormData) => { setLoading(true); setError(''); diff --git a/src/components/register-card.tsx b/src/components/register-card.tsx index 264222c..fe7c372 100644 --- a/src/components/register-card.tsx +++ b/src/components/register-card.tsx @@ -18,9 +18,14 @@ export const RegisterCard = ({ callback }: RegisterCardProps) => { const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const user = useUser(); - - if (user) + + if (user) { + if (callback?.startsWith(process.env.NEXT_PUBLIC_BASE_PATH!)) + callback = callback.replace(process.env.NEXT_PUBLIC_BASE_PATH!, ''); + return redirect(callback ?? '/'); + } + const submit = (data: FormData) => { setLoading(true); setError(''); diff --git a/src/helpers/permissions.ts b/src/helpers/permissions.ts index c4967ce..f11f549 100644 --- a/src/helpers/permissions.ts +++ b/src/helpers/permissions.ts @@ -31,7 +31,7 @@ export const hasPermission = (use */ export const requirePermission = (userPermission: number | null | undefined, ...requestedPermission: (T | T[])[]) => { if (!hasPermission(userPermission, ...requestedPermission)) - redirect('/unauthorized'); + redirect('/forbidden'); } /** @@ -62,5 +62,5 @@ export const hasArcadePermission = (userArcadePermission: number | null | undefi export const requireArcadePermission = (userArcadePermission: number | null | undefined, userPermission: number | null | undefined, ...requestedPermissions: (ArcadePermissions | ArcadePermissions[])[]) => { if (!hasArcadePermission(userArcadePermission, userPermission, ...requestedPermissions)) - redirect('/unauthorized'); + redirect('/forbidden'); }