rename SessionDependency to DbSessionDependency

This commit is contained in:
maxDorninger
2025-03-28 15:22:36 +01:00
parent 1a558361f4
commit 11c45a9d57
6 changed files with 21 additions and 18 deletions

View File

@@ -8,10 +8,12 @@ from jwt.exceptions import InvalidTokenError
from pydantic import BaseModel
from auth.config import AuthConfig
from database import SessionDependency
from database import DbSessionDependency
from database.users import User
# TODO: evaluate FASTAPI-Users package
class Token(BaseModel):
access_token: str
token_type: str
@@ -28,7 +30,7 @@ oauth2_scheme = OAuth2PasswordBearer(tokenUrl="api/v1/token")
router = APIRouter()
async def get_current_user(db: SessionDependency, token: str = Depends(oauth2_scheme)) -> User:
async def get_current_user(db: DbSessionDependency, token: str = Depends(oauth2_scheme)) -> User:
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",

View File

@@ -6,7 +6,7 @@ from fastapi.security import OAuth2PasswordRequestForm
from sqlmodel import select
from auth import Token, create_access_token, router
from database import SessionDependency
from database import DbSessionDependency
from database.users import User
@@ -21,7 +21,7 @@ def get_password_hash(password: str) -> str:
return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8")
def authenticate_user(db: SessionDependency, email: str, password: str) -> bool | User:
def authenticate_user(db: DbSessionDependency, email: str, password: str) -> bool | User:
"""
:param email: email of the USER
@@ -39,7 +39,7 @@ def authenticate_user(db: SessionDependency, email: str, password: str) -> bool
@router.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
db: SessionDependency,
db: DbSessionDependency,
) -> Token:
user = authenticate_user(db,form_data.username, form_data.password)
if not user: