Show Records Connected to the Logged-in User

This article will guide you through the process of displaying only the records that are connected to the logged-in user.


One of Knack's most powerful features is the ability for users to login and view their own private records and not the records of 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 their connected records using the Custom CRM sample app.


In order to set up your app to show records connected to the logged in user, you will need to have Users enabled in your app.

You can read more on Users and how to enabled them here.


Define Your User Roles

Once you have Users enabled in your app, you can define the types of user roles that will interact with your Live App. 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 types of user roles could be: EmployeesManagersEditorsAdmins, etc. You can create multiple roles for different needs. For example, an app used in a school may have on for student and one for teacher.

To add a user role, click the green "+" button next to the User Roles list in the Data section of your Builder.


This will prompt you to name your user role, then a new user role will be added to your app. You can add fields to that user role just like any other table. 

The main Accounts table 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, that user will be present in both that user role table and in the main Accounts table. This is useful if you need to work with every user regardless of the role.

After you add your user role, you can add a record to start with in the "Records" section of the Builder. Any user records you add will be able to log in to your app on the pages you have allowed.

You can read more on adding and managing user records here.


Connect Users With Records

Now that you have user roles set up, you can connect your records with your users. For example, Projects connected to Employees, Invoices connected to Clients, or Orders connected to Sales Reps.

If you don't already have an table with records you want to connect to your user, you can read more on adding tables here.

To connect records to your users, you will need to add a new connection field. In this example, we will connect the Contacts table to a Sales Rep user role.

While viewing the table in the Data section of the Builder, click the green "+" button in the Connections right side bar.


This will then open a modal popup where you can select which table or user role to connect with. In this case, we are connecting the Contacts table to the Sales Rep user role.


Once you have selected which table to connect with, you will be prompted to define how those tables will connect. In this example, we want each Contact to connect with one Sales Rep and each Sales Rep to connect with many Contacts.

This will allow Sales Reps to be assigned multiple Contacts where each Contact will only have a single Sales Rep assigned to them.


You can learn more about different types of connections here.


When you are done defining the connection type, click "Add Connection" and this will create a new connection field in your table. Here, you can see the Contacts table now has a "Sales Rep" connection field.


This connection field will appear as a lookup where you can choose which record to connect with. For example, when you edit any of the Client records, you can now use the connection field to select a Sales Rep.


Add Login Pages to Your Live App

Now that the tables, user roles, and connections are setup, we need to add a page for your users to login and view their records.

A new login page can be added by clicking the green "+" button on the Pages section of the Builder and then selecting "Login Page" from the options.


This will prompt you to choose who can login to the page. In this case, we want to select "Limit permissions to a specific user role."

For this example, we are limiting permission to Sales Reps.


Learn more about security settings available with user logins to help ensure the security of your Live App pages.

Once you have created your new login page, you will be prompted to add a view. When adding a view, you will select the view type, the table that the view will display, and what type of records from that table will display.

For this example, we selected a grid view type which will display Contacts connected to the logged-in Sales Rep.


Next, you will be asked if you want to add any additional links to your view. This is not necessary for this example, but you can read more about action links here.

Once you have finished setting up your view, click the "Confirm" button to add the grid to the login page. Now, you have a view showing records connected to the logged in user.

You can always check the "Source" section of the view settings to confirm which records are being shown in a view.

Login to the Live App & Test

Now that you have set up your login page and view to show records connected to the logged in user, you can confirm it is working correctly by viewing the Live App. To view the Live App, click the "Go to Live App" button or the open icon in the top menu.



You can log in with a user record from the user role you used in this example. You should then see the view you added working with the records connected to your user.

In this example, you can see all Contacts connected to the logged in Sales Rep, Johnny Gonzalez.


How do I add a login to an existing page?

If you already have a page you want to use to show records connected to the logged in user, you can add a login by selecting the drop down next to the page name. There, you can select "Require Login", and you will be prompted to add a login.


You can learn more about logins here.

How do I add a view to an existing page?

If you already have login page in your app, you can add a view by selecting the "Add View" button while viewing that page. This will start the view setup process where you can create view that shows records connected to the logged in user.


You can learn more about adding and managing views here.

How do I show records connected to the logged in user's group?

It's also possible to connect your users to a company or organization and show records connected to that company. For example, a Teacher may want to login and only see students connected to their Department.