Hi @Javiera Osorio Mardones (Alumno),
Welcome to the Microsoft Q&A Platform!
It seems like you need a dynamic user permission management system that is simple to extend without hardcoding. Since your job application platform has users acquiring and losing permissions depending on what they do, your approach to updating permissions in controllers and maintaining them in the user schema works. This may, however, be difficult to manage as your platform expands. With the resources of Azure, you can easily develop this system and secure your platform.
- To have a more scalable and easier-to-manage permission system, adopt Role-Based Access Control (RBAC) via Azure Active Directory (Azure AD) or Azure AD B2C. This will allow you to dynamically define roles and assign them to users instead of hardcoding permissions.
- Steps to Deploy RBAC: Register your application in the Azure portal.
- Define roles like "Applicant," "Recruiter," or "Admin" in the app registration.
- Assign them to users or groups as needed.
- Use libraries like @azure/msal-node for your Node.js Backend to authenticate and validate tokens. After a user is authenticated, Azure AD places the user's roles in the token's claims. Your backend can now authorize requests based on the roles.
- Use @azure/msal-react for your React Frontend to authenticate users and get tokens. Conditionally render elements or block access to parts of your app based on the roles in the token.
- For situations where permissions need to be renewed depending on what the user is performing (e.g., a job application), you can:
- Update the user's Azure AD roles to include additional permissions.
- Store custom permissions as Azure AD B2C custom attributes and include them with the token. Your application can then read these attributes to ascertain access levels.
Microsoft Documentation for Reference:
Use role-based access control in your Node.js web application
Manage user access in Azure Active Directory B2C
Roles and resource access control - Azure AD B2C
Hope the above provided information help in better understanding and help you resolve the issue, if you have any further concerns or queries, please feel free to reach out to us.
If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.