@@ -107,12 +133,16 @@ const PermissionCRUD = () => {
{permission.name}
- handleEdit(permission)}>
-
-
- handleDelete(permission._id)}>
-
-
+ {canUpdate && (
+ handleEdit(permission)}>
+
+
+ )}
+ {canDelete && (
+ handleDelete(permission._id)}>
+
+
+ )}
))}
diff --git a/src/Pages/Protected/Roles/RolesListPage/index.jsx b/src/Pages/Protected/Roles/RolesListPage/index.jsx
index 3da43012..6d17c3db 100644
--- a/src/Pages/Protected/Roles/RolesListPage/index.jsx
+++ b/src/Pages/Protected/Roles/RolesListPage/index.jsx
@@ -24,11 +24,7 @@ export default function RolesListPage() {
const storagedUserString = localStorage.getItem("@App:user");
const storagedUser = JSON.parse(storagedUserString);
- const response = await APIUsers.get("role", {
- headers: {
- Authorization: `Bearer ${storagedUser.token}`,
- },
- });
+ const response = await APIUsers.get("role");
const data = response.data;
if (Array.isArray(data)) {
@@ -44,7 +40,7 @@ export default function RolesListPage() {
fetchRoleForm();
}, []);
- const hasPermission = checkAction(permissions, "create");
+ const hasPermission = checkAction(permissions, "perfis_criar");
const handleSubmit = () => {
navigate("/perfis/criar");
diff --git a/src/Pages/Protected/Roles/RolesUpdatePage/index.jsx b/src/Pages/Protected/Roles/RolesUpdatePage/index.jsx
index 5b1afa5f..777f4e3a 100644
--- a/src/Pages/Protected/Roles/RolesUpdatePage/index.jsx
+++ b/src/Pages/Protected/Roles/RolesUpdatePage/index.jsx
@@ -154,7 +154,7 @@ export default function RolesUpdatePage() {
placeholder="Digite o nome da permissão"
/>
*/}
-
+
{/* Lista de permissões */}
Lista de Permissões
diff --git a/src/Pages/Protected/Users/userUpdatePage/index.jsx b/src/Pages/Protected/Users/userUpdatePage/index.jsx
index 69013558..26369dbf 100644
--- a/src/Pages/Protected/Users/userUpdatePage/index.jsx
+++ b/src/Pages/Protected/Users/userUpdatePage/index.jsx
@@ -38,8 +38,8 @@ export default function UserUpdatePage() {
const [isEmailValid, setIsEmailValid] = useState(true);
const [isCelularValid, setIsCelularValid] = useState(true);
- const canDelete = checkAction(permissions, "delete");
- const canUpdate = checkAction(permissions, "update");
+ const canDelete = checkAction(permissions, "usuarios_deletar");
+ const canUpdate = checkAction(permissions, "usuarios_editar");
useEffect(() => {
const loadRoles = async () => {
diff --git a/src/Services/BaseService/index.js b/src/Services/BaseService/index.js
index 514ecaff..4f2041e1 100644
--- a/src/Services/BaseService/index.js
+++ b/src/Services/BaseService/index.js
@@ -1,4 +1,6 @@
import axios from "axios";
+import { getToken } from "../Functions/loader";
+
const baseBenefitsURL =
import.meta.env.VITE_BENEFIT_DB_URL || "http://localhost:3003/";
@@ -9,14 +11,23 @@ const baseUserURL =
const APIUsers = axios.create({
baseURL: baseUserURL,
+ headers: {
+ Authorization: `Bearer ${getToken()}`,
+ },
});
const APIBank = axios.create({
baseURL: baseBankURL,
+ headers: {
+ Authorization: `Bearer ${getToken()}`,
+ },
});
const APIBenefits = axios.create({
baseURL: baseBenefitsURL,
+ headers: {
+ Authorization: `Bearer ${getToken()}`,
+ },
});
export { APIUsers, APIBank, APIBenefits };
diff --git a/src/Services/Permissions/permissionsService.js b/src/Services/Permissions/permissionsService.js
index 8b5aa85b..e2d6bcbf 100644
--- a/src/Services/Permissions/permissionsService.js
+++ b/src/Services/Permissions/permissionsService.js
@@ -27,11 +27,7 @@ export const getAllPermissions = async () => {
if (!token) {
throw new Error("No token found");
}
- const response = await APIUsers.get("/permission", {
- headers: {
- Authorization: `Bearer ${token}`,
- },
- });
+ const response = await APIUsers.get("/permission");
return response.data;
} catch (error) {
console.error("Erro ao buscar permissões:", error.response?.data || error);
diff --git a/src/Services/RoleService/roleService.js b/src/Services/RoleService/roleService.js
index 143d4e0b..7a246cba 100644
--- a/src/Services/RoleService/roleService.js
+++ b/src/Services/RoleService/roleService.js
@@ -27,9 +27,7 @@ export const createRole = async (roleData) => {
moduleName: "users",
action: "create",
},
- headers: {
- Authorization: `Bearer ${token}`,
- },
+
});
return response.data;
} catch (error) {
@@ -45,9 +43,7 @@ export const getAllRoles = async () => {
throw new Error("No token found");
}
const response = await APIUsers.get("/role", {
- headers: {
- Authorization: `Bearer ${token}`,
- },
+
});
return response.data;
} catch (error) {
@@ -62,11 +58,7 @@ export const getRoleById = async (id) => {
if (!token) {
throw new Error("No token found");
}
- const response = await APIUsers.get(`/role/${id}`, {
- headers: {
- Authorization: `Bearer ${token}`,
- },
- });
+ const response = await APIUsers.get(`/role/${id}`, );
return response.data;
} catch (error) {
console.error("Erro ao buscar role:", error);
@@ -83,9 +75,7 @@ export const assignPermissionsToRole = async (roleId, permissions) => {
const response = await APIUsers.put(`/roles/${roleId}/permissions`, {
permissions,
}, {
- headers: {
- Authorization: `Bearer ${token}`,
- },
+
});
return response.data;
@@ -121,9 +111,7 @@ export const updateRole = async (id, roleData) => {
moduleName: "users",
action: "update",
},
- headers: {
- Authorization: `Bearer ${token}`,
- },
+
});
return response.data;
} catch (error) {
@@ -158,9 +146,7 @@ export const deleteRole = async (id) => {
moduleName: "users",
action: "delete",
},
- headers: {
- Authorization: `Bearer ${token}`,
- },
+
});
return response.data;
} catch (error) {