final
This commit is contained in:
@@ -13,7 +13,10 @@ async def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(s
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token")
|
||||
return user
|
||||
async def check_roles(user=Depends(get_current_user)):
|
||||
if user.get("admin") != True:
|
||||
user_check = await db.list_user(user["user_id"])
|
||||
if not user_check:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found")
|
||||
if user_check.admin != True:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Access denied")
|
||||
return user
|
||||
|
||||
|
||||
Reference in New Issue
Block a user