renderAuthorize.js 690 Bytes
Newer Older
徐立's avatar
徐立 committed
1 2 3 4 5 6 7 8 9
/* eslint-disable eslint-comments/disable-enable-pair */

/* eslint-disable import/no-mutable-exports */
let CURRENT = 'NULL';

/**
 * use  authority or getAuthority
 * @param {string|()=>String} currentAuthority
 */
10 11 12 13 14
const renderAuthorize = (Authorized) => (currentAuthority) => {
	if (currentAuthority) {
		if (typeof currentAuthority === 'function') {
			CURRENT = currentAuthority();
		}
徐立's avatar
徐立 committed
15

16 17 18 19 20 21 22 23 24
		if (
			Object.prototype.toString.call(currentAuthority) === '[object String]' ||
			Array.isArray(currentAuthority)
		) {
			CURRENT = currentAuthority;
		}
	} else {
		CURRENT = 'NULL';
	}
徐立's avatar
徐立 committed
25

26
	return Authorized;
徐立's avatar
徐立 committed
27 28 29
};

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