I have a basic web site on FastAPI. I would like to implement login/logout (Auth) behavior similar to Flask-login, i.e. allow access to a function/path with decorator like @login\_required or FastAPI Dependecy injection.

I found [fastapi-login](https://fastapi-login.readthedocs.io/) module that advertised to be similar to Flask-login, but it thin on documentation to say the least. It is totally missing logout

So, I'm looking for help to correctly implement logout.

Here is file structure:

```
├── app
│   ├── __init__.py
│   └── main.py
├── requirements.txt
└── templates
    └── login.html.j2 

```

and working app.main.py code without logout:

```
from fastapi.responses import RedirectResponse, HTMLResponse
from fastapi.security import OAuth2PasswordRequestForm
from fastapi_login import LoginManager 
from fastapi_login.exceptions import InvalidCredentialsException
from fastapi.templating import Jinja2Templates
from sys import path

app = FastAPI()

SECRET = "secret-key"

templates = Jinja2Templates(directory="templates")

manager = LoginManager(SECRET, tokenUrl="/auth/login", use_cookie=True)
manager.cookie_name = "some-name"

DB = {"username": {"password": "1234567"}}  # unhashed

@manager.user_loader
def load_user(username: str):
   user = DB.get(username)
   return user

@app.post("/auth/login")
def login(data: OAuth2PasswordRequestForm = Depends()):
   username = data.username
   password = data.password
   user = load_user(username)
   if not user:
       raise InvalidCredentialsException
   elif password != user['password']:
       raise InvalidCredentialsException
   access_token = manager.create_access_token(
       data={"sub": username}
   )
   resp = RedirectResponse(url="/private", status_code=status.HTTP_302_FOUND)
   manager.set_cookie(resp, access_token)
   return resp

@app.get("/private")
def getPrivateendpoint(_=Depends(manager)):
   return "You are an authentciated user"

@app.get("/public")
def getPublicendpoint():
   return "You are just a user"

@ app.get("/auth/login", response_class=HTMLResponse)
def login(request: Request):
   context = {'request': request, }
   return templates.TemplateResponse("login.html.j2", context)

```

I have attempted logout function (below), but it does not work. it just redirects to login page, but does not actually remove access.

```
@ app.get("/auth/logout", response_class=HTMLResponse)
def logout(request: Request):
   response = RedirectResponse(url="/auth/login")
   response.delete_cookie("Authorization", domain="localtest.me")
   return response

```

I suspect that something wrong with delete\_cookie params, but has no clue what these params should be:

```
response.delete_cookie("Authorization", domain="localtest.me") 

```

Here is the template:

```
<link rel="stylesheet" href="https://unpkg.com/twinklecss@1.1.0/twinkle.min.css"/>
</head>
<body>
   <div class="flex p-4 m-6 justify-center">
       <form class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4" method="POST" action="/auth/login" >
         <div class="mb-4">
           <label class="block text-gray-700 text-sm font-bold mb-2" for="username">
             Username
           </label>
           <input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="username" name="username" type="text">
         </div>
         <div class="mb-6">
           <label class="block text-gray-700 text-sm font-bold mb-2" for="password">
             Password
           </label>
           <input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 mb-3 leading-tight focus:outline-none focus:shadow-outline" id="password" name="password" type="password">
         </div>
         <div class="flex items-center justify-between">
           <button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline">
             Sign In
           </button>
         </div>
       </form>
     </div>
</body>
</html>

```

Please help with logout.