Secure all endpoints behind auth
This commit is contained in:
@@ -70,6 +70,16 @@ def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]):
|
||||
raise credentials_exception
|
||||
return user
|
||||
|
||||
def auth_is_admin(token: str = Depends(oauth2_scheme)):
|
||||
user = get_current_user(token=token)
|
||||
if not user.is_admin:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Not authorized to perform this action",
|
||||
headers={"WWW-Authenticate": "Bearer"}
|
||||
)
|
||||
return True
|
||||
|
||||
def create_first_user():
|
||||
print("Checking for admin user")
|
||||
with Session(engine) as db:
|
||||
|
||||
Reference in New Issue
Block a user