I am currently working on a project that involves multiple user types (SuperUser - SchoolAdmin - Teacher).
Each role has specific privileges to access certain elements.
How can I dynamically hide elements based on the logged-in user's role using *ngIf?
Here is the link to the project on StackBlitz, where I have provided a live preview for guidance.
In the app, you will find common services under auth. This folder contains the login service and authentication guard.
Check out models >> enum to see the user type enum.
In the sign-in component, you will find the form that defines the user type.
Review the routes to see the expected roles assigned to each component.
Testing users:
This user should be directed to the school-list page
Admin (with super user role): [email protected] Password: 12345
This user should be directed to the dashboard
Student (with student role): [email protected] Password: 12345
For instance, if I want to hide an element on the dashboard visible only to the super user role, how can I achieve this?
I understand that I can use ngIf, but I am unsure of the correct way to implement it within NgIf. I need practical examples based on my code.
Update: The issue has been resolved, so I have removed the test users.