feat(auth): add auth middleware

- refactored chat routes to use request.user instead of doing authentication in every route
This commit is contained in:
Anuraag Jain 2023-12-28 22:15:54 +02:00
parent 8370465796
commit a01b112f7f
5 changed files with 63 additions and 89 deletions

View file

@ -55,13 +55,13 @@ def extract_token_from_auth_header(auth_header: str):
def verify_token(request):
try:
bearer = request.headers["authorization"]
if bearer:
token = bearer[len("Bearer ") :]
decoded = jwt.decode(
authorization = request.headers["authorization"]
if authorization:
_, token = authorization.split()
decoded_token = jwt.decode(
token, JWT_SECRET_KEY, options={"verify_signature": False}
)
return decoded
return decoded_token
else:
return None
except Exception as e: