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

37 lines
887 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);
const userData = {
id: data.user.id,
name: data.user.name,
nickname: data.user.nickname,
language: data.user.lang || 'es',
darkMode: data.user.userConfig.darkMode,
}
state.setUser(userData);
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
};
}