diff --git a/back/main.py b/back/main.py index 0d9a438..e7542a1 100644 --- a/back/main.py +++ b/back/main.py @@ -167,7 +167,7 @@ async def login_for_access_token( @app.get("/api/users/me/", response_model=schema.User) -async def read_users_me( +async def read_users_me( #!!!!!!!!!!! current_user: Annotated[User, Depends(get_current_active_user)] ): return current_user diff --git a/back/utils.py b/back/utils.py index 41f4bc3..d128168 100644 --- a/back/utils.py +++ b/back/utils.py @@ -9,7 +9,7 @@ from passlib.context import CryptContext from sqlalchemy.orm import Session from sqlalchemy import select -from .db import SessionLocal, database +from .db import Session, database from .models import UserDatabase from .schema import Token, TokenData, UserInDB, User @@ -42,14 +42,15 @@ def get_password_hash(password): # проблема здесь -def get_user(db: SessionLocal, email: str): - user_with_required_email = db.query(UserDatabase).filter(UserDatabase.email == email).one() +def get_user(db: Session, email: str): + user_with_required_email = db.query(UserDatabase).filter(UserDatabase.email == email).first() + print(user_with_required_email) if user_with_required_email: - return UserInDB(user_with_required_email) + return user_with_required_email return None -def authenticate_user(db: SessionLocal, email: str, password: str): +def authenticate_user(db: Session, email: str, password: str): user = get_user(db, email) if not user: return False @@ -69,7 +70,7 @@ def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None return encoded_jwt -async def get_current_user(db: SessionLocal, token: Annotated[str, Depends(oauth2_scheme)]): +async def get_current_user(db: Session, token: Annotated[str, Depends(oauth2_scheme)]): credentials_exception = HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Could not validate credentials",