Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/components/elements/PermissionRoute.tsx
7461 views
1
import React from 'react';
2
import { Route } from 'react-router-dom';
3
import { RouteProps } from 'react-router';
4
import Can from '@/components/elements/Can';
5
import { ServerError } from '@/components/elements/ScreenBlock';
6
7
interface Props extends Omit<RouteProps, 'path'> {
8
path: string;
9
permission: string | string[] | null;
10
}
11
12
export default ({ permission, children, ...props }: Props) => (
13
<Route {...props}>
14
{!permission ? (
15
children
16
) : (
17
<Can
18
matchAny
19
action={permission}
20
renderOnError={
21
<ServerError title={'Access Denied'} message={'You do not have permission to access this page.'} />
22
}
23
>
24
{children}
25
</Can>
26
)}
27
</Route>
28
);
29
30