Open Closed

How to apply role based authorization to the module in angular framework. #9300


User avatar
0
sahanaacharya created

How to apply role based authorization to the module. We have to hide menu items which is on the 'Side Navbar', as per role based authorization. Give me the example of angular framework.


3 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Hi,

    CurrentUser object has roles array on it. You can easily access roles of the user easily in client-side:


    And, at the backend, CurrentUser has an IsInRole method for this check:

    Our @Angular team can answer if need a more complex scenario for angular

  • User Avatar
    0
    sahanaacharya created

    Need more clarification and example to handle authorization. Please give me the example to hide side navbar menu items according to specific roles.

  • User Avatar
    0
    sumeyye.kurtulus created
    Support Team Angular Expert

    Hello! To manage visibility based on user roles, you can use the invisible or requiredPolicy property. These properties help control which navigation items are shown depending on the user's permissions.

    You can find more details about these properties in the ABP Framework codebase here.

    For example, if you decide to use the invisible property, you can modify the navigation items like this:

     import { ABP, AuthService, RoutesService } from '@abp/ng.core';
     ...
      protected routes = inject(RoutesService);
      updateRouteVisibility(name: string, invisible: boolean) {
        const route = this.routes.find(route => route.name === name);
        // const invisible = --you can add your own logic to decide visibility-- 
        if (route) {
          this.routes.patch(name, {
            invisible: invisible,
          } as Partial<ABP.Route>);
        }
      }
      ...
    

    Let me know if you need further assistance on that.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on June 13, 2025, 11:37