fix problems

This commit is contained in:
2026-08-05 12:22:45 +03:00
parent 4e14972cf6
commit 2da58c7483
8 changed files with 113 additions and 121 deletions
@@ -3,13 +3,13 @@ from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from src.models.configs_read.env import env_settings
from src.models.pydantic_models.model import UserOut
from src.service.auth.auth import auth
from src.service.auth.auth import CurrentUserService, auth_service
router=APIRouter(prefix="/protected")
oauth2_schema=OAuth2PasswordBearer(tokenUrl="/protected/token", refreshUrl="/protected/refresh")
@router.post("/token")
async def get_access_token(request: Request,response:Response, form_data:OAuth2PasswordRequestForm=Depends())->dict: # noqa: B008
async def get_access_token(request: Request,response:Response,auth:CurrentUserService=Depends(auth_service), form_data:OAuth2PasswordRequestForm=Depends())->dict: # noqa: B008
access_token, refresh_token=auth.login(form_data_email=form_data.username, form_data_password=form_data.password, request=request)
@@ -25,7 +25,7 @@ async def get_access_token(request: Request,response:Response, form_data:OAuth2P
@router.post("/refresh")
async def get_refresh_token(request:Request,response:Response, refresh_token: str = Cookie())->dict:
async def get_refresh_token(request:Request,response:Response, refresh_token: str = Cookie(), auth:CurrentUserService=Depends(auth_service))->dict: # noqa: B008
access_token, refresh_token= auth.refresh_token(refresh_token=refresh_token,request=request)
@@ -41,12 +41,12 @@ async def get_refresh_token(request:Request,response:Response, refresh_token: st
return {"access_token":access_token, "token_type": "bearer"}
async def get_current_user(token:str = Depends(oauth2_schema)) -> UserOut:
async def get_current_user(token:str = Depends(oauth2_schema), auth:CurrentUserService=Depends(auth_service)) -> UserOut: # noqa: B008
return UserOut.model_validate(auth.get_current_user(token))
@router.get("/logout")
async def logout(response:Response,refresh_token: str = Cookie(),current_user:UserOut=Depends(get_current_user))->bool: # noqa: B008
async def logout(response:Response,refresh_token: str = Cookie(),auth:CurrentUserService=Depends(auth_service),current_user:UserOut=Depends(get_current_user))->bool: # noqa: B008
response.delete_cookie("refresh_token")
return auth.logout(refresh_token)
@@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends
from src.models.pydantic_models.model import UserOut
from src.service.users_crud.users_crud import crud_service
from src.web.protected_routes.routes import get_current_user
from src.web.protected_routes.auth_routes import get_current_user
router=APIRouter(prefix="/user")