MCPcopy Create free account
hub / github.com/MankaiHuang/screen-visualization / getAuthority

Function getAuthority

src/utils/authority.js:10–33  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

8import { reloadAuthorized } from './Authorized'; // use localStorage to store the authority info, which might be sent from server in actual project.
9
10export function getAuthority (str) {
11 const authorityString =
12 typeof str === 'undefined' && localStorage ? localStorage.getItem('userRole') : str; // authorityString could be admin, "admin", ["admin"]
13
14 let authority;
15
16 try {
17 if (authorityString) {
18 authority = JSON.parse(authorityString);
19 }
20 } catch (e) {
21 authority = authorityString;
22 }
23
24 if (typeof authority === 'string') {
25 return [authority];
26 } // preview.pro.ant.design only do not use in your production.
27 // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
28
29 if (!authority) {
30 return ['user'];
31 }
32 return authority;
33}
34export function setAuthority (authority) {
35 const proAuthority = typeof authority === 'string' ? [authority] : authority;
36 localStorage.setItem('antd-pro-authority', JSON.stringify(proAuthority)); // auto reload

Callers 3

authority.test.jsFile · 0.90
Authorized.jsFile · 0.90
reloadAuthorizedFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected