0
0
Fork 0
salix-front-mindshore-fork2/src/composables/useRole.js

30 lines
646 B
JavaScript
Raw Normal View History

import { useState } from './useState';
import axios from 'axios';
2022-03-11 10:41:23 +00:00
export function useRole() {
const state = useState();
async function fetch() {
const { data } = await axios.get('/api/accounts/acl');
const roles = data.roles.map(userRoles => userRoles.role.name);
state.setUser(data.user);
state.setRoles(roles);
}
2022-03-28 07:06:36 +00:00
function hasAny(roles) {
const roleStore = state.getRoles();
2022-03-11 10:41:23 +00:00
for (const role of roles) {
if (roleStore.value.indexOf(role) !== -1) return true;
2022-03-11 10:41:23 +00:00
}
return false;
}
return {
fetch,
2022-03-11 10:41:23 +00:00
hasAny,
state
2022-03-11 10:41:23 +00:00
};
}