How to Manage User Role Access
Learn how to restrict protected pages to specific user roles in Knack. Configure page-level access settings and use page rules to control element visibility by role.
Goal
Use this guide to control which user roles can access specific protected pages in your app. For example, you might create an Admin Panel that only Administrators can access, or separate dashboards for Managers and Employees—each with different levels of access based on their role.
Prerequisites
- You have a protected page already created (see "How to Create a Login-Protected Page")
- You have at least one user role table set up in your app
- For conceptual background on user roles and permissions, see "User Management Fundamentals"
Step-by-Step Instructions
Setting Access to All Logged-In Users
- Navigate to the Pages section in the Builder.
- Click on the protected page you want to configure.
- Click the Access tab in the page settings panel.
- Locate the "Which logged-in users can access this page?" section.
- Select All logged-in users (this is the default setting).
- Click Save to apply the changes.
When to use this: Choose this option when all authenticated users should have access to the same content, regardless of their assigned role.
Restricting Access to Specific User Roles
- Navigate to the Pages section in the Builder.
- Click on the protected page you want to configure.
- Click the Access tab in the page settings panel.
- Locate the "Which logged-in users can access this page?" section.
- Select Specific user roles only.
- Check the box next to each role that should have access to this page. You can select one role or multiple roles.
- Click Save to apply the changes.
When to use this: Choose this option when different types of users need different levels of access—such as separating what Administrators, Managers, and Employees can see.
Using Page Rules for Element-Level Control
When multiple user roles can access the same page, you can use page rules to show or hide specific elements based on the user's role.
- Navigate to the page that multiple roles can access.
- Click on the element you want to control (e.g., a form, table, or button).
- In the element settings, click the Rules tab.
- Click Add Rule to create a new page rule.
- Configure the rule:
- WHEN: Set the condition to check the logged-in user's role (e.g., "Logged-in user's role is Admin")
- THEN: Choose Show this element or Hide this element
- Click Save to apply the rule.
- Repeat for other elements that should have role-based visibility.
Example: On a company event calendar accessible to all roles, you could add a page rule to show the "Add New Event" form only when the logged-in user is assigned the HR role.
Important: Page rules control visibility but should not be relied upon for security. Always use page-level protection to secure sensitive content.
Verifying User Access
To test that role-based access is working correctly:
- Click Preview to open your Live App.
- Log in with a user account that has the required role.
- Verify that the protected page is accessible and displays correctly.
- Log out and log in with a user account that does NOT have the required role.
- Verify that the page is not accessible or not visible in the navigation menu.
- If access is not working as expected, return to the Access tab and verify the role selections.
Result
Your protected page now restricts access based on user roles. Only users assigned to the selected roles can view the page after logging in. Users without the required roles will not see the page in the navigation menu and will be prevented from accessing it directly.
Updated 3 months ago
