import { useState } from './useState'; import axios from 'axios'; 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); } function hasAny(roles) { const roleStore = state.getRoles(); for (const role of roles) { if (roleStore.value.indexOf(role) !== -1) return true; } return false; } return { fetch, hasAny, state }; }