fix
This commit is contained in:
@@ -38,16 +38,24 @@ async def get_current_user(token: str = Depends(oauth2_scheme), db: Session = De
|
|||||||
headers={"WWW-Authenticate": "Bearer"},
|
headers={"WWW-Authenticate": "Bearer"},
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
print(f"DEBUG AUTH: Decoding token: {token[:10]}...")
|
||||||
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
||||||
username: str = payload.get("sub")
|
username: str = payload.get("sub")
|
||||||
|
print(f"DEBUG AUTH: Username from token: {username}")
|
||||||
if username is None:
|
if username is None:
|
||||||
|
print("DEBUG AUTH: Username is None")
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
token_data = schemas.TokenData(username=username)
|
token_data = schemas.TokenData(username=username)
|
||||||
except JWTError:
|
except JWTError as e:
|
||||||
|
print(f"DEBUG AUTH: JWTError: {e}")
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
|
|
||||||
user = db.query(models.User).filter(models.User.username == token_data.username).first()
|
user = db.query(models.User).filter(models.User.username == token_data.username).first()
|
||||||
if user is None:
|
if user is None:
|
||||||
|
print(f"DEBUG AUTH: User {token_data.username} not found in DB")
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
|
|
||||||
|
print(f"DEBUG AUTH: User found: {user.username}, Is Admin: {user.is_admin}")
|
||||||
return user
|
return user
|
||||||
|
|
||||||
async def get_current_admin_user(current_user: models.User = Depends(get_current_user)):
|
async def get_current_admin_user(current_user: models.User = Depends(get_current_user)):
|
||||||
|
|||||||
Reference in New Issue
Block a user