Add the users service
Click the following link to clone the news aggregator app to use as a starting point.
You don’t need to have completed the News Aggregator tutorial to do this tutorial.
However, you may want to complete one of the ‘Start Here’ tutorials if you haven’t yet.
We’ll use Anvil’s built-in Users Service to manage signup and login with a single line of Python.
There are various sign-in options included in the Users Service, including Google, Facebook, Microsoft Azure AD, Office 365 and more. You can find all the sign-in options here.
Step 1: Add the Users Service
Let’s start by adding the Users Service.
You’ll see a screen which allows you to select from the available authentication methods, and provides you with some configuration options. For now, let’s choose the following:
Supported sign-in methods:
- Email + password
New user registration:
- Allow visitors to sign up
- New user accounts can be used right away
Your setup should look something like this:
Step 2: Display the login form
We want our users to log in or sign up when the app loads.
Go to ‘Code’ view of your ‘Homepage’ Form, and add this line to the Form’s
__init__ method, underneath the
Run your app, and you’ll see the login form pop up. Click ‘Sign up for a new account’, and fill in the boxes. (Remember, we aren’t requiring users to confirm their email addresses, so you can use dummy email addresses for testing).
You’ll see some print statements in the Output panel after you sign up - the Users Service has automatically created a ‘Users’ Data Table for you, and added a new row to the table!
Stop your app, click on ‘Data Tables’ in the App Browser, and select the ‘Users’ Table from the tabs at the top. You’ll see your sign in information has been stored in the table:
That’s the Users Service set up and ready to go. Nice work!
On to Chapter 2 where we will link news articles to users.