Updating the application
In this section, we’ll update the routes to use the new authentication model. Lastly, we’ll update the POST route for adding an event to populate the events field in the user’s record.
Updating the user sign-in route
In routes/users.py
, update the imports:
from fastapi import APIRouter, Depends, HTTPException, status from fastapi.security import OAuth2PasswordRequestForm from auth.jwt_handler import create_access_token from models.users import User
We have imported the OAuth2PasswordRequestForm
class from FastAPI’s security module. This will be injected into the sign-in route to retrieve the credentials sent over: username and password. Let’s update the sign_user_in()
route function:
async def sign_user_in(user: OAuth2PasswordRequestForm = Depends()) -> dict: user_exist = await User.find_one(User.email == user.username) .. ...