Live Chat

We'll need to share your messages (and your email address if you're logged in) with our live chat provider, Drift. Here's their privacy policy.

If you don't want to do this, you can email us instead at contact@anvil.works.

Multi-User Applications with Anvil
« Anvil Tutorials

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:

Edit this app

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:

And if you have your own Anvil instance you can also use:


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:

  anvil.users.login_with_form()

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:

@anvil.server.callable
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 = anvil.server.call('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.


Publishing | 3:42 - 4:34


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

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

Congratulations - if you’ve followed the three Anvil Essentials tutorials, you have a solid foundation in Anvil.

Watch the Anvil Uplink tutorial to learn how to connect Anvil to your own Python installation running on any machine.

You can search or browse all our tutorials from the Learning Centre.