renderAuthorize.js 651 Bytes
Newer Older
1 2 3 4 5 6
/* eslint-disable import/no-mutable-exports */
let CURRENT = 'NULL';
/**
 * use  authority or getAuthority
 * @param {string|()=>String} currentAuthority
 */
7 8
const renderAuthorize = Authorized => currentAuthority => {
  if (currentAuthority) {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
9
    if (typeof currentAuthority === 'function') {
10
      CURRENT = currentAuthority();
11
    }
12
    if (
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
13 14
      Object.prototype.toString.call(currentAuthority) === '[object String]' ||
      Array.isArray(currentAuthority)
15 16 17 18 19 20 21
    ) {
      CURRENT = currentAuthority;
    }
  } else {
    CURRENT = 'NULL';
  }
  return Authorized;
22 23 24 25
};

export { CURRENT };
export default Authorized => renderAuthorize(Authorized);