forked from sk1982/actaeon
add forbidden and not found pages
This commit is contained in:
parent
8b2e5096f4
commit
1b79472e34
14
src/app/(centered)/forbidden/page.tsx
Normal file
14
src/app/(centered)/forbidden/page.tsx
Normal 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>);
|
||||
}
|
@ -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>);
|
||||
}
|
||||
|
26
src/components/error-page-nav-buttons.tsx
Normal file
26
src/components/error-page-nav-buttons.tsx
Normal 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>
|
||||
</>);
|
||||
};
|
@ -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('');
|
||||
|
@ -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('');
|
||||
|
@ -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');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user