Authorized.js 942 Bytes
Newer Older
afc163's avatar
afc163 committed
1 2 3
import React from 'react';
import RenderAuthorized from '@/components/Authorized';
import Exception from '@/components/Exception';
4
import { getAuthority } from '@/utils/authority';
afc163's avatar
afc163 committed
5 6
import { formatMessage } from 'umi/locale';
import Link from 'umi/link';
7
import Redirect from 'umi/redirect';
afc163's avatar
afc163 committed
8

9 10
const Authority = getAuthority();
const Authorized = RenderAuthorized(Authority);
afc163's avatar
afc163 committed
11

12 13
export default ({ children }) => {
  let noMatch = (
afc163's avatar
afc163 committed
14 15
    <Exception
      type="403"
afc163's avatar
afc163 committed
16
      desc={formatMessage({ id: 'app.exception.description.403' })}
afc163's avatar
afc163 committed
17 18 19 20
      linkElement={Link}
      backText={formatMessage({ id: 'app.exception.back' })}
    />
  );
21 22 23 24 25
  // if Authority === ['guest'] redirect to /user/login
  // You can implement the logic here.
  if (Authority.join('') === 'guest') {
    noMatch = <Redirect to="/user/login" />;
  }
afc163's avatar
afc163 committed
26
  return (
27
    <Authorized authority={children.props.route.authority} noMatch={noMatch}>
afc163's avatar
afc163 committed
28 29 30 31
      {children}
    </Authorized>
  );
};