diff --git a/back/main.py b/back/main.py index e98f547..c9f994d 100644 --- a/back/main.py +++ b/back/main.py @@ -7,7 +7,7 @@ from fastapi.templating import Jinja2Templates from fastapi.requests import Request from pydantic import json - +from typing import Any from starlette.staticfiles import StaticFiles import requests @@ -168,8 +168,11 @@ async def login_for_access_token( return {"access_token":access_token} -@app.get("/api/users/me/", response_model=None) # -async def read_users_me(current_user: Depends(get_current_active_user)): #Annotated[schemas.User, Depends(get_current_active_user)]): +# @app.get("/api/users/me/", response_model=schemas.User) # +# async def read_users_me(current_user: Annotated[schemas.User, Depends(get_current_active_user)]): +# return current_user #schemas.User(id=current_user.id, email=current_user.email, name=current_user.name, surname=current_user.surname, disabled=current_user.disabled, items=current_user.items) +@app.get("/api/users/me/", response_model=schemas.User) # +async def read_users_me(current_user: Annotated[schemas.User, Depends(get_current_active_user)]) -> Any: return current_user #schemas.User(id=current_user.id, email=current_user.email, name=current_user.name, surname=current_user.surname, disabled=current_user.disabled, items=current_user.items) diff --git a/back/schemas.py b/back/schemas.py index 62cf65c..afce18a 100644 --- a/back/schemas.py +++ b/back/schemas.py @@ -45,6 +45,7 @@ class User(BaseModel): class Config: orm_mode = True + arbitrary_types_allowed=True class UserInDB(User): hashed_password: str diff --git a/back/utils.py b/back/utils.py index 954e9e5..4b70789 100644 --- a/back/utils.py +++ b/back/utils.py @@ -30,7 +30,6 @@ def get_password_hash(password): return pwd_context.hash(password) -# проблема здесь def get_user(db: Session, email: str): user_with_required_email = db.query(models.User).filter(models.User.email == email).first() if user_with_required_email: @@ -75,7 +74,8 @@ async def get_current_user(db: Session, token: Annotated[str, Depends(oauth2_sch user = get_user(db, email=token_data.email) if user is None: raise credentials_exception - return user + return schemas.User(id=user.id, email=user.email, name=user.name, surname=user.surname, disabled=user.disabled, items=user.items) + # return user async def get_current_active_user(