Batteries-included authentication flow in Dash with Dash Pages.
This has landing pages and functions to run the entire authentication flow:
- home
- login
- logout
- register
- forgot password
- change password
This uses flask-login on the backend, taking some inspiration from the very useful dash-flask-login. Data is held in users.db.
The provided .env.example is just an example. Copy that file to a .env file and fill in the details. It's set up this way so you don't accidentally expose your credentials in git. The app won't run correctly if .env doesn't have the required values filled out.
# with plain virtualenv
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python create_tables.py
python app.py
# with pipenv
pip install pipenv
pipenv install --ignore-pipfile
pipenv python create_tables.py
pipenv run python app.py
# with poetry
pip install poetry
poetry run python create_tables.py
poetry run python app.py
# either: deactivate virtual environment
deactivate- this uses MailJet as the email API. You need a free MailJet API key
- your send-from email and API key/secret need to be entered in
.env - if you want to use a different email provider, change the
send_password_keyfunction inutilities/auth.py - add pages in
pages/. Make sure to register the page at a path withregister_page(__name__, pathname="/path") - the app's basic layout and routing happens in
app.py - app is created and auth is built in
server.py - config is in
utilities/config.txtandutilities/config.py
I've provided a Procfile for Heroku, there are many resources for Heroku deployment.
My preferred host is Fly.io. I've included a Dockerfile, .dockerignore, and fly.toml for an example.
# first time
fly launch
# after any change, deploy an updated version with
fly deploy