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

37 lines
829 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() {
2023-04-26 10:04:55 +00:00
const { data } = await axios.get('VnUsers/acl');
2022-11-24 06:21:45 +00:00
const roles = data.roles.map((userRoles) => userRoles.role.name);
const userData = {
id: data.user.id,
name: data.user.name,
nickname: data.user.nickname,
lang: data.user.lang || 'es',
2022-11-24 06:21:45 +00:00
};
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,
2022-11-24 06:21:45 +00:00
state,
2022-03-11 10:41:23 +00:00
};
2022-11-24 06:21:45 +00:00
}