I would like to redirect users to the login page, when they are not logged in. Here is my code: from fastapi import ( Depends, FastAPI, HTTPException, status, Body, Request ) from fastapi.encoders import jsonable_encoder from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm from fastapi.responses import HTMLResponse, RedirectResponse import app.models as models import app.database as database from datetime import datetime, timedelta from jose import JWTError, jwt from starlette.responses import FileResponse from fastapi_login import LoginManager from fastapi_login.exceptions import InvalidCredentialsException from fastapi import Cookie import re app = FastAPI() oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") manager = LoginManager(SECRET_KEY, token_url="/auth/login", use_cookie=True) manager.cookie_name = "token" @app.get("/") @app.get("/item") async def read_index(user=Depends(manager)): try: return FileResponse('item.html') except status.HTTP_401_UNAUTHORIZED: return RedirectResponse(url="/login", status_code=status.HTTP_302_FOUND) However, when I access this page: localhost:8000/item, I get the following: {"detail":"Not authenticated"} Continue reading...