renderAuthorize.js 864 B

12345678910111213141516171819202122232425262728293031323334
  1. /* eslint-disable eslint-comments/disable-enable-pair */
  2. /* eslint-disable import/no-mutable-exports */
  3. let CURRENT = 'NULL'
  4. /**
  5. * use authority or getAuthority
  6. * @param {string|()=>String} currentAuthority
  7. */
  8. const renderAuthorize = Authorized => currentAuthority => {
  9. if (currentAuthority) {
  10. if (typeof currentAuthority === 'function') {
  11. CURRENT = currentAuthority()
  12. }
  13. if (Object.prototype.toString.call(currentAuthority) === '[object Promise]') {
  14. currentAuthority.then(value => {
  15. CURRENT = value
  16. })
  17. }
  18. if (
  19. Object.prototype.toString.call(currentAuthority) === '[object String]' ||
  20. Array.isArray(currentAuthority)
  21. ) {
  22. CURRENT = currentAuthority
  23. }
  24. } else {
  25. CURRENT = 'NULL'
  26. }
  27. return Authorized
  28. }
  29. export { CURRENT }
  30. export default Authorized => renderAuthorize(Authorized)