add forbidden and not found pages

This commit is contained in:
sk1982 2024-03-27 20:32:39 -04:00
parent 8b2e5096f4
commit 1b79472e34
6 changed files with 67 additions and 6 deletions

View File

@ -0,0 +1,14 @@
import { ErrorPageNavButtons } from '@/components/error-page-nav-buttons';
import { NoSymbolIcon } from '@heroicons/react/24/outline';
export default function ForbiddenPage() {
return (<main className="flex flex-col w-full h-full justify-center items-center gap-4 text-center">
<NoSymbolIcon className="w-48 mb-10" />
<header className="text-2xl font-semibold mb-5">
You do not have permissions to do that.
</header>
<section className="flex gap-2">
<ErrorPageNavButtons />
</section>
</main>);
}

View File

@ -1,3 +1,14 @@
import { ErrorPageNavButtons } from '@/components/error-page-nav-buttons';
import { XCircleIcon } from '@heroicons/react/24/outline';
export default function NotFound() {
return (<div className="flex w-full h-full items-center justify-center">Not Found.</div>)
return (<main className="flex flex-col w-full h-full justify-center items-center gap-4 text-center">
<XCircleIcon className="w-48 mb-10" />
<header className="text-2xl font-semibold mb-5">
The link you requested could not be found.
</header>
<section className="flex gap-2">
<ErrorPageNavButtons />
</section>
</main>);
}

View File

@ -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 (<>
<Button size="lg" variant="flat" onPress={() => router.back()}>
Go Back
</Button>
<Link href="/">
<Button size="lg" variant="flat">
Go Home
</Button>
</Link>
<Link href="/dashboard">
<Button size="lg" variant="flat">
Go to Dashboard
</Button>
</Link>
</>);
};

View File

@ -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('');

View File

@ -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('');

View File

@ -31,7 +31,7 @@ export const hasPermission = <T extends UserPermissions | ArcadePermissions>(use
*/
export const requirePermission = <T extends UserPermissions | ArcadePermissions>(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');
}