UDT-006: Middleware de Autorización (RBAC enforcement) #10
@@ -1,6 +1,4 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useAuthStore } from '@/stores/authStore'
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
@@ -12,17 +10,10 @@ import { useRoles } from '../../roles/hooks/useRoles'
|
||||
import { RolPermisosEditor } from '../components/RolPermisosEditor'
|
||||
|
||||
export function RolPermisosPage() {
|
||||
const navigate = useNavigate()
|
||||
const user = useAuthStore((s) => s.user)
|
||||
const [selectedRol, setSelectedRol] = useState<string | null>(null)
|
||||
|
||||
const { data: roles, isLoading: loadingRoles } = useRoles()
|
||||
|
||||
if (!user || user.rol !== 'admin') {
|
||||
void navigate('/', { replace: true })
|
||||
return null
|
||||
}
|
||||
|
||||
const rolesActivos = roles?.filter((r) => r.activo) ?? []
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useAuthStore } from '@/stores/authStore'
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
@@ -15,14 +14,8 @@ import { EditRolForm } from '../components/RolForm'
|
||||
export function EditRolPage() {
|
||||
const navigate = useNavigate()
|
||||
const { codigo } = useParams<{ codigo: string }>()
|
||||
const user = useAuthStore((s) => s.user)
|
||||
const { data: rol, isLoading, isError } = useRol(codigo)
|
||||
|
||||
if (!user || user.rol !== 'admin') {
|
||||
void navigate('/', { replace: true })
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex justify-center py-8">
|
||||
<Card className="w-full max-w-lg">
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useAuthStore } from '@/stores/authStore'
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
@@ -11,12 +10,6 @@ import { CreateRolForm } from '../components/RolForm'
|
||||
|
||||
export function NewRolPage() {
|
||||
const navigate = useNavigate()
|
||||
const user = useAuthStore((s) => s.user)
|
||||
|
||||
if (!user || user.rol !== 'admin') {
|
||||
void navigate('/', { replace: true })
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex justify-center py-8">
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Link, useNavigate } from 'react-router-dom'
|
||||
import { useAuthStore } from '@/stores/authStore'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
Card,
|
||||
@@ -11,14 +10,6 @@ import {
|
||||
import { RolesList } from '../components/RolesList'
|
||||
|
||||
export function RolesPage() {
|
||||
const navigate = useNavigate()
|
||||
const user = useAuthStore((s) => s.user)
|
||||
|
||||
if (!user || user.rol !== 'admin') {
|
||||
void navigate('/', { replace: true })
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex justify-center py-8">
|
||||
<Card className="w-full max-w-4xl">
|
||||
|
||||
Reference in New Issue
Block a user