One of Knack's most powerful features is the ability for users to login, view their own page, and access their own records - not records belonging to other users.
For example, you may want to have your customers login and see their invoices, or have your employees login to see their jobs for the day.
This article walks through how to enable logged-in users to only see these connected records.
Step 1 is to set up your database to store user records and connect those to the records you want each user to see when they log in.
The way permissions and access work with Knack is by defining which User Roles can access which pages in your app and what views go on each page.
Examples of different user roles could be Employees, Managers, Editors, Admins, etc. You can create multiple roles for different needs. For example, a school app may have on for student and one for teacher.
You'll want to add at least one user role, so click the "+ADD" button next to the User Roles list in your database. If you haven't enabled users for your app yet you'll be prompted with a wizard to do that. Accept the defaults to continue.
Create a name for your role and add the new object. You can add fields to that user role just like any other object.
- The main Accounts object will contain the user records for all of your roles. This is essentially a master list of all your user records. If you add a new user to a role, it will be present in both that role and in the main Accounts object. This is useful if you need to work with every user regardless of the role.
After you add your user role, click “Records” to add your users. These users will be able to log in to your app. You can also set up your pages so users can register on their own.
Now you need an object for the records you want your users to manage when they log in. It could be projects for employees, invoices for clients, orders for sales reps, etc.
Add a new object and then add a connection to the user role you created above. Here’s an example of connecting an Orders object to a Sales Rep User Role:
First, click “Add Connection” in the right side bar menu.
Then follow the prompt to create a Connection, or relationship, between your User Role and a specific Object, such as Orders.
When you edit any of those order records in your database you can now use the connection field to select a sales rep.
When this user (Steve Smith) logs in he’ll be able to view this order record.
Now that our database is setup we can add pages for your users to login and access. We can show the records connected to the logged-in user with views like tables and forms. There are two ways to add these: either by adding a new page or by adding views to an existing page.
Knack Tip: Read more about security settings available with user logins to help ensure the security of your Live App pages.
First create a new start page by clicking the “+Add” button from your page menu on the left. Note: the first time you visit the Page Builder you will be prompted to create your first page.
Set the page to require a login with limited permissions requiring the sales rep role and click Continue.
The next step is to select your object with the Select an Object button. At the top of that object list, you’ll notice options to add a view connected to the logged in user (click the very small arrow to expand your choices).
These views will only display records that you’ve connected to the user role. In this case, you will choose Orders connected to the logged-in user:
Finally you’ll need to select the types of views you want on this page. In this case we’ll add a table that contains Orders connected to the logged-in Sales Rep. Then click Continue, confirm the name of the new page and click the Add New Page button to actually add this page.
Let’s assume you have already created a page. We need to make sure a login is assigned to this page for the User Role of your choice. Keeping with the Sales Rep example, click the “gear” icon to view the page options.
Once selected, choose the “Require Login” option:
Follow the prompts to choose the Role you want to assign to the page. Once the login setting is applied you will see the login page appear.
Now that the page has a login you can add the User specific View, such as a Table View, to the page. Choose a View from the view menu:
Your choices for views related to the logged-in user will be listed for you:
Upon successfully adding the view, you can quickly verify if the view is connected to the logged-in user by checking for the key icon in the new view. Now the records in this table will reflect those connected to the logged-in Sales Rep and no other users.
Hover the “view app” menu in the upper right, then select your new page and test it:
You can log in with a user record you added above. You should then see the view you added working with the records connected to your user.
It's also possible to connect your users to a company or organization and show records connected to that company.