Adding Database Backed User Authentication to FastAPI

🔖 code  python  fastapi 

So you’re excited about FastAPI and you’ve been following the excellent documentation. At some point, you’ll come to the section on security which sets you up with a login view, some utilities for hashing passwords and a dependency injected current user object.

It works great! The only problem is now you are left with a working application, but your user database consists of a hardcoded dictionary. Obviously, this will not do for a real application.

In this tutorial, we will replace our fake users database dictionary with a real database backed user table. In the next part, we’ll add a registration endpoint so that people can sign up for accounts and login to your application.

Read more...