Skip to content

Commit

Permalink
updated calling userroles by authenticating (#2423)
Browse files Browse the repository at this point in the history
  • Loading branch information
abilpraju-aot authored Dec 13, 2024
1 parent 29a0d03 commit aafafc2
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions forms-flow-web/src/components/PrivateRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ const PrivateRoute = React.memo((props) => {
store.dispatch(setUserToken(instance.getToken()));
// Set Cammunda/Formio Base URL
setApiBaseUrlToLocalStorage();

// Fetch user roles and update the local storage
getUserRoles()
.then((res) => {
if (res) {
const { data = [] } = res;
const roles = data.map((role) => role.name);
localStorage.setItem("allAvailableRoles", JSON.stringify(roles));
}
})
.catch((error) => console.error("Error fetching roles", error));

// Get formio roles
store.dispatch(
getFormioRoleIds((err) => {
Expand All @@ -136,6 +148,7 @@ const PrivateRoute = React.memo((props) => {
})
);
};


const keycloakInitialize = useCallback(() => {
let instance = tenantId ? kcServiceInstance(tenantId) : kcServiceInstance();
Expand All @@ -155,21 +168,6 @@ const PrivateRoute = React.memo((props) => {
}
}, [props.store, kcInstance, tenantId]);

// Remove this line since 'allRoles' is not used elsewhere
// const [allRoles, setAllRoles] = useState([]);

// Updated useEffect to fetch and set user roles without the 'allRoles' assignment
useEffect(() => {
getUserRoles()
.then((res) => {
if (res) {
const { data = [] } = res;
const roles = data.map((role) => role.name);
localStorage.setItem("allAvailableRoles", JSON.stringify(roles)); // Set roles in localStorage
}
})
.catch((error) => console.error("Error fetching roles", error));
}, [dispatch]);

useEffect(() => {
if (tenantId && MULTITENANCY_ENABLED) {
Expand Down

0 comments on commit aafafc2

Please sign in to comment.