index.d.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import * as React from 'react';
  2. import { RouteProps } from 'react-router';
  3. type authorityFN = (currentAuthority?: string) => boolean;
  4. type authority = string | Array<string> | authorityFN | Promise<any>;
  5. export type IReactComponent<P = any> =
  6. | React.StatelessComponent<P>
  7. | React.ComponentClass<P>
  8. | React.ClassicComponentClass<P>;
  9. interface Secured {
  10. (authority: authority, error?: React.ReactNode): <T extends IReactComponent>(
  11. target: T,
  12. ) => T;
  13. }
  14. export interface AuthorizedRouteProps extends RouteProps {
  15. authority: authority;
  16. }
  17. export class AuthorizedRoute extends React.Component<
  18. AuthorizedRouteProps,
  19. any
  20. > {}
  21. interface check {
  22. <T extends IReactComponent, S extends IReactComponent>(
  23. authority: authority,
  24. target: T,
  25. Exception: S,
  26. ): T | S;
  27. }
  28. interface AuthorizedProps {
  29. authority: authority;
  30. noMatch?: React.ReactNode;
  31. }
  32. export class Authorized extends React.Component<AuthorizedProps, any> {
  33. static Secured: Secured;
  34. static AuthorizedRoute: typeof AuthorizedRoute;
  35. static check: check;
  36. }
  37. declare function renderAuthorize(currentAuthority: string): typeof Authorized;
  38. export default renderAuthorize;