Logged in user

Set up filters on record collections based on the logged in user.

We often want to create collection views where we filter records by the logged in user. This enables us to only show specific records that are associated with the logged in user.

In this video, learn how to:

  • Set up filters based on the logged in user

  • Preview as another app user to test these filters

  • Set up filters when using a User List

  • Choose between filters and record-level database permission rules

  • Set up record-level permission rules to control record access at database level

As shown in the video above, filters only prevent certain records from being displayed to the user on a particular collection view. If you only ever want users to be able to access specific records, you should set up record-level permissions to restrict access at the API layer.

When should I use filters vs record-level permission rules?

If you're happy for your app users to be able to access all records in a particular collection but you also want to create a view that filters the records to only show those associated with the app user, then collection filters will work well for your use case.

However, if your app has data that only some users should be able to access, then you should set up record-level permissions to restrict data access. Database permission rules will override any filters you have set on your collection views. In other words, if you've set permission rules that determine that a user with a particular role shouldn't be able to access particular records, those records will never be shown to the user in your app.

How do I filter records by the logged in user if I'm using an external data source?

If you're using an external data source (like Airtable, PostgreSQL etc.), you can still filter data based on the logged in user as long as your data collections are set up in one of two ways:

  1. You have created a relationship field between the relevant collection you want to filter on and the Noloco User table

  2. You have relationship fields linking the relevant collection and a Users table in your external data source and you have connected a User List to sync your users information from your external Users table into the Noloco User table. If you watch the video above, you'll see that our demo real estate app is set up in this way, where we have an Airtable collection of Estate Agents that's related to the Properties collection. We have added a User List to sync the user information from our Estate Agents table to the Noloco User table.

Example filter based on the logged in user

Once you're happy that the necessary relationships are in place to link Noloco Users to the relevant collection, you can then filter the collection view based on the 'Logged in User'.

In the below example we are applying a filter on the Properties collection. We only want to show the logged in user (or Estate Agent in this case) their assigned Properties.

We talk through this specific example in the video linked above.

Last updated