Data Storage and Security
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.
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?
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.
We display the login form by running:
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.
If we log in as
firstname.lastname@example.org, we see one To-Do list. If we log in as
email@example.com, 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
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.