I am trying to validate token in fastapi middleware but this seems impossible. As i am thinking middleware needs to make next call although its not required. I am not able to find any good solution to handle token in one go in this python-fastapi backend. Any help is appreciated.
@app.middleware("http")
async def add_middleware_here(request: Request, call_next):
token = request.headers["Authorization"]
try:
verification_of_token = verify_token(token)
if verification_of_token:
response = await call_next(request)
return response
except InvalidSignatureError as er:
raise HTTPException(status_code=401)