Table of Contents

Show Records Connected to the Logged-in User

Danielle Kellogg Updated by Danielle Kellogg

Scenario

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

Requirements

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.

Steps

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 Employees, Managers, Editors, Admins, 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 Schema 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 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, 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, next 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 object with records you want to connect to your user, you can read more on adding objects here.

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

While viewing the object in the Schema 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 object or user role to connect with. In this case we are connecting the Contacts object to the Sales Rep user role.

Once you have selected which object to connect with, you will be prompted to define how those objects 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 read 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 object. Here you can see the Contacts object, 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 objects, user roles and connections are setup, next 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.

Read 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 object that the view will display and what type of records from that object will display.

For this example, we selected a Table 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 table 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.

Notes

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 read 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 read 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.

 

How did we do?

Show Records Connected To The Logged-in User's Company Or Other Group

Create an Admin User Role to View All Records

Contact