forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermissionRoute.tsx
More file actions
28 lines (26 loc) · 819 Bytes
/
PermissionRoute.tsx
File metadata and controls
28 lines (26 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import React from 'react';
import { Route } from 'react-router-dom';
import { RouteProps } from 'react-router';
import Can from '@/components/elements/Can';
import { ServerError } from '@/components/elements/ScreenBlock';
interface Props extends Omit<RouteProps, 'path'> {
path: string;
permission: string | string[] | null;
}
export default ({ permission, children, ...props }: Props) => (
<Route {...props}>
{!permission ? (
children
) : (
<Can
matchAny
action={permission}
renderOnError={
<ServerError title={'Access Denied'} message={'You do not have permission to access this page.'} />
}
>
{children}
</Can>
)}
</Route>
);