Add check for non-existing user in auth user middleware
This commit is contained in:
parent
49bc902bb9
commit
dd6ccd19b1
1 changed files with 5 additions and 1 deletions
|
|
@ -12,6 +12,10 @@ def get_auth_user(auth: HTTPAuthorizationCredentials = Depends(HTTPBearer()), db
|
|||
try:
|
||||
decoded_token = verify_token(auth.credentials)
|
||||
auth_user = get_user_by_id(db, int(decoded_token["sub"]))
|
||||
|
||||
if auth_user is None:
|
||||
raise HTTPException(status_code=401)
|
||||
|
||||
return auth_user
|
||||
except JWTError:
|
||||
raise HTTPException(status_code=403, detail="Invalid token")
|
||||
raise HTTPException(status_code=401, detail="Invalid token")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue