Summary
In this chapter, you’ve seen a very basic, but quite representative, implementation of two versions of an authentication mechanism. You learned how FastAPI enables the use of standard-compliant authentication methods and implemented one of the simplest possible yet effective solutions – without persisting the authentication data and storing the JWT in localStorage
.
You have learned how elegant and flexible FastAPI is when it comes to defining granular roles and permissions, especially with MongoDB, with the aid of Pydantic as the middleman. This chapter was focused exclusively on JWTs as the means of communication because it is the primary and most popular tool in SPAs nowadays, and it enables great connectivity between services or microservices. JWT mechanisms shine when you need to develop different applications with the same FastAPI and MongoDB-powered backend—for instance, a React web application and a React Native or Flutter-based mobile app.
...