Data Storage and Security

4m 44s

When your application supports multiple different users, it’s important to ensure that they can’t access each other’s data. In this video, we show how straightforward this can be with Anvil.

We start with the online TODO-list app from our last tutorial, and turn it into a multi-user public service.

Hands on

To explore this app in the Anvil editor, click this button:

Feel free to use it as a starting point for writing your own multi-user Create, Read, Update, Delete (CRUD) app.

Want to know more?

Read about the Users Service or Data Tables in the Anvil reference manual.

Topics Covered

Users Service | 0:32 - 0:45

The Users Service handles user signup and login with a single line of Python. Usernames and password hashes are stored automatically in a Data Table.

There are various sign-in options in the Users Service, and all can be enabled/disabled: - username and password - Google - Facebook - Microsoft Azure AD and Office 365

And if you have your own Anvil instance you can also use: - local Active Directory - X.509 certificates

Linking To-Do items to users | 0:45 - 1:03

We add a link column to link each row of the Reminders table to a row of the Users table. This will link to the user that each reminder belongs to.

Logging users in | 1:03 - 1:30

We display the login form by running:


Client-writable views | 1:30 - 3:42

We set the permissions on our Reminders table back to ‘No access’ for Form code (the default).

We then create a client-writable view specific to the logged-in user:

def get_reminders():
  current_user = anvil.users.get_user()
  if current_user is not None:
    return app_tables.reminders.client_writable(owner=current_user)

In the client, we get a reference to this view:

  self.my_reminders ='get_reminders')

Everywhere we were using app_tables.reminders, we now use self.my_reminders. Everything behaves as if the table contained only this user’s reminders.

If we log in as, we see one To-Do list. If we log in as, we see a different To-Do list. Both lists are in the Reminders table, but each user can only access their own reminders.

Publishing | 3:42 - 4:34

Now we’re confident in sharing this publicly.

Try it for yourself

Build this app for yourself - Sign up and follow along, or watch more tutorials in the Anvil Learning Centre.

Next up

Head to the Anvil Learning Centre for more tutorials.