modified: src/App.jsx
modified: src/components/AppShell.jsx modified: src/config/api.js modified: src/config/permissions.js modified: src/data/mockData.js modified: src/hooks/useAgenda.js modified: src/hooks/useAuth.js modified: src/mappers/appointmentMapper.js modified: src/pages/AgendaPage.jsx modified: src/pages/AuthPages.jsx modified: src/pages/HomePage.jsx modified: src/pages/MedicalRecordsPage.jsx modified: src/pages/MessagesPage.jsx modified: src/pages/NotFoundPage.jsx modified: src/pages/PatientsPage.jsx modified: src/pages/ReportsPage.jsx modified: src/pages/TeamPage.jsx modified: src/pages/UsersPage.jsx modified: src/pages/VisitsPage.jsx modified: src/repositories/authRepository.js new file: src/repositories/availabilityRepository.js modified: src/repositories/communicationRepository.js modified: src/repositories/patientRepository.js modified: src/repositories/professionalRepository.js modified: src/repositories/profileRepository.js modified: src/repositories/reportRepository.js modified: src/repositories/repositoryUtils.js modified: src/repositories/settingsRepository.js modified: src/repositories/userRepository.js modified: src/repositories/visitRepository.js
This commit is contained in:
@@ -2,6 +2,7 @@ const SUPABASE_URL = import.meta.env.VITE_SUPABASE_URL || 'https://yuanqfswhberk
|
||||
const SUPABASE_ANON_KEY = import.meta.env.VITE_SUPABASE_ANON_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ'
|
||||
|
||||
const AUTH_SESSION_KEY = 'mediconnect.auth.session'
|
||||
export const AUTH_SESSION_CHANGED_EVENT = 'mediconnect:auth-session-changed'
|
||||
|
||||
export const apiConfig = {
|
||||
apiUrl: import.meta.env.VITE_API_BASE_URL || import.meta.env.VITE_SUPABASE_FUNCTIONS_URL || `${SUPABASE_URL}/functions/v1`,
|
||||
@@ -34,12 +35,14 @@ export function getAuthSession() {
|
||||
export function saveAuthSession(session) {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.sessionStorage.setItem(AUTH_SESSION_KEY, JSON.stringify(session))
|
||||
notifyAuthSessionChanged()
|
||||
}
|
||||
}
|
||||
|
||||
export function clearAuthSession() {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.sessionStorage.removeItem(AUTH_SESSION_KEY)
|
||||
notifyAuthSessionChanged()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,3 +88,7 @@ function cleanHeaders(headers) {
|
||||
Object.entries(headers).filter(([, value]) => value !== undefined && value !== null),
|
||||
)
|
||||
}
|
||||
|
||||
function notifyAuthSessionChanged() {
|
||||
window.dispatchEvent(new Event(AUTH_SESSION_CHANGED_EVENT))
|
||||
}
|
||||
|
||||
@@ -7,6 +7,28 @@ export const ROLES = {
|
||||
PACIENTE: 'paciente',
|
||||
}
|
||||
|
||||
const ROLE_ALIASES = {
|
||||
admin: ROLES.ADMIN,
|
||||
administrador: ROLES.ADMIN,
|
||||
administrator: ROLES.ADMIN,
|
||||
gestor: ROLES.GESTOR,
|
||||
gestao: ROLES.GESTOR,
|
||||
gestao_coordenacao: ROLES.GESTOR,
|
||||
coordenacao: ROLES.GESTOR,
|
||||
coordenador: ROLES.GESTOR,
|
||||
manager: ROLES.GESTOR,
|
||||
medico: ROLES.MEDICO,
|
||||
medica: ROLES.MEDICO,
|
||||
doctor: ROLES.MEDICO,
|
||||
physician: ROLES.MEDICO,
|
||||
secretaria: ROLES.SECRETARIA,
|
||||
secretario: ROLES.SECRETARIA,
|
||||
secretary: ROLES.SECRETARIA,
|
||||
receptionist: ROLES.SECRETARIA,
|
||||
paciente: ROLES.PACIENTE,
|
||||
patient: ROLES.PACIENTE,
|
||||
}
|
||||
|
||||
// Rotas permitidas por role ('*' = todas)
|
||||
const ROLE_ROUTES = {
|
||||
admin: '*',
|
||||
@@ -142,15 +164,33 @@ export const ROLE_NAV_ITEMS = {
|
||||
|
||||
// Verifica se um role pode acessar uma rota
|
||||
export function canAccess(role, pathname) {
|
||||
if (!role) return false
|
||||
const allowed = ROLE_ROUTES[role]
|
||||
const normalizedRole = normalizeRole(role)
|
||||
if (!normalizedRole) return false
|
||||
const allowed = ROLE_ROUTES[normalizedRole]
|
||||
if (allowed === '*') return true
|
||||
if (!Array.isArray(allowed)) return false
|
||||
return allowed.some((route) => pathname === route || pathname.startsWith(route + '/'))
|
||||
}
|
||||
|
||||
// Verifica se um role tem uma capacidade específica
|
||||
export function hasCapability(role, capability) {
|
||||
return ROLE_CAPABILITIES[role]?.[capability] ?? false
|
||||
const normalizedRole = normalizeRole(role)
|
||||
return ROLE_CAPABILITIES[normalizedRole]?.[capability] ?? false
|
||||
}
|
||||
|
||||
export function normalizeRole(role) {
|
||||
const normalized = normalizeRoleKey(role)
|
||||
return ROLE_ALIASES[normalized] ?? null
|
||||
}
|
||||
|
||||
function normalizeRoleKey(role) {
|
||||
return String(role ?? '')
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^a-z0-9]+/g, '_')
|
||||
.replace(/^_+|_+$/g, '')
|
||||
}
|
||||
|
||||
// Rótulos amigáveis para cada role
|
||||
|
||||
Reference in New Issue
Block a user