Authorized.js 966 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
      linkElement={Link}
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
18 19
      redirect="/user/login"
      backText="back to login"
afc163's avatar
afc163 committed
20 21
    />
  );
22 23
  // if Authority === ['guest'] redirect to /user/login
  // You can implement the logic here.
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
24
  if (Authority === 'guest' || Authority.join('') === 'guest') {
25 26
    noMatch = <Redirect to="/user/login" />;
  }
afc163's avatar
afc163 committed
27
  return (
28
    <Authorized authority={children.props.route.authority} noMatch={noMatch}>
afc163's avatar
afc163 committed
29 30 31 32
      {children}
    </Authorized>
  );
};