Authorized.tsx 858 B

1234567891011121314151617181920212223242526272829
  1. import CheckPermissions from './CheckPermissions';
  2. import { IAuthorityType } from './CheckPermissions';
  3. import Secured from './Secured';
  4. import check from './CheckPermissions';
  5. import AuthorizedRoute from './AuthorizedRoute';
  6. import React from 'react';
  7. interface IAuthorizedProps {
  8. authority: IAuthorityType;
  9. noMatch?: React.ReactNode;
  10. }
  11. type IAuthorizedType = React.FunctionComponent<IAuthorizedProps> & {
  12. Secured: typeof Secured;
  13. check: typeof check;
  14. AuthorizedRoute: typeof AuthorizedRoute;
  15. };
  16. const Authorized: React.FunctionComponent<IAuthorizedProps> = ({
  17. children,
  18. authority,
  19. noMatch = null,
  20. }) => {
  21. const childrenRender: React.ReactNode = typeof children === 'undefined' ? null : children;
  22. const dom = CheckPermissions(authority, childrenRender, noMatch);
  23. return <>{dom}</>;
  24. };
  25. export default Authorized as IAuthorizedType;