|
|
@@ -1,17 +1,14 @@
|
|
|
// use localStorage to store the authority info, which might be sent from server in actual project.
|
|
|
export function getAuthority() {
|
|
|
// return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];
|
|
|
- let authority = localStorage.getItem('antd-pro-authority');
|
|
|
- if (authority) {
|
|
|
- if (authority.includes('[')) {
|
|
|
- authority = JSON.parse(authority);
|
|
|
- } else {
|
|
|
- authority = [JSON.parse(authority)];
|
|
|
- }
|
|
|
- } else {
|
|
|
- authority = ['admin'];
|
|
|
+ const authorityString = localStorage.getItem('antd-pro-authority');
|
|
|
+ let authority;
|
|
|
+ try {
|
|
|
+ authority = JSON.parse(authorityString);
|
|
|
+ } catch (e) {
|
|
|
+ authority = [authorityString];
|
|
|
}
|
|
|
- return authority;
|
|
|
+ return authority || ['admin'];
|
|
|
}
|
|
|
|
|
|
export function setAuthority(authority) {
|