renderAuthorize.js 695 B

123456789101112131415161718192021222324252627
  1. /* eslint-disable import/no-mutable-exports */
  2. let CURRENT = 'NULL';
  3. /**
  4. * use authority or getAuthority
  5. * @param {string|()=>String} currentAuthority
  6. */
  7. const renderAuthorize = Authorized => {
  8. return currentAuthority => {
  9. if (currentAuthority) {
  10. if (currentAuthority.constructor.name === 'Function') {
  11. CURRENT = currentAuthority();
  12. }
  13. if (
  14. currentAuthority.constructor.name === 'String' ||
  15. currentAuthority.constructor.name === 'Array'
  16. ) {
  17. CURRENT = currentAuthority;
  18. }
  19. } else {
  20. CURRENT = 'NULL';
  21. }
  22. return Authorized;
  23. };
  24. };
  25. export { CURRENT };
  26. export default Authorized => renderAuthorize(Authorized);