When you use Security Filters, you normally set the Require user authentication option on the Security > Require Sign-In pane. Once a user signs in, AppSheet knows the user's email address. You can then use the user's email address to filter the data shown to that user. In addition to filtering data, you can also limit users to particular tables, views, and actions. For each table, you can customize who has permissions to see the backend data with Access Mode.
When you use Security Filters, you often include a field in each record that identifies the "owner" of the record. Typically this field contains the owner's email address. When adding a new record to a table, you can use the USEREMAIL() function in that field's InitialValue property to initialize it with the user's email address.
Security filters are optional yes/no expressions associated with each table in the app. They typically use the user's email address, and possibly other data values, to limit the data shown to the app user.
To limit access by User Email:
- [EmailColumn] = USEREMAIL()
To limit access by User Email Domain:
- CONTAINS(USEREMAIL(), [EmailDomainColumn])
You can limit access by User Email but allow a specific manager to have access. In this example, we assume the manager's email address is "firstname.lastname@example.org". Then specify a security filter like:
- OR(USEREMAIL() = "email@example.com", USEREMAIL() = [EmailColumn])
You can limit access by User Email but allow any manager to have access. Do this by creating a Managers table that contains the email addresses of all managers. Then specify a security filter like:
- OR(IN(USEREMAIL(), Managers[Email]), USEREMAIL() = [EmailColumn])
You can build more complex Security Filters.
You can filter based on the Department name contained in the Employees table. The security filter would be:
- LOOKUP(USEREMAIL(), Employees, Email, Department) = "Admin"
You can filter the Customers table so that each sales representative sees only their own customers. If you have a separate CustomersToReps lookup table having columns CustomerId and SalesRepEmail, the security filter for the Customers table would be:
- IN([CustomerId], SELECT(CustomersToReps[CustomerId], [SalesRepEmail] = USEREMAIL()))
However, be aware that more complex Security Filters like the one above are typically inefficient when used with large datasets.
Warning: Avoid USERNAME() in Security Filters because it is unreliable. Providers like Google, only return the user's name if that user has enabled Google+ on their account.
You can watch this webinar on Security Filters to learn more!