From 57ff496844a81fc1077125b212da2fa74ddff759 Mon Sep 17 00:00:00 2001 From: Anaz Date: Tue, 25 Feb 2025 14:15:18 +0400 Subject: [PATCH] correction of the auth service --- api/v1/auth.py | 4 ++-- services/auth_service.py | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/api/v1/auth.py b/api/v1/auth.py index d1d58ce..d6287fe 100644 --- a/api/v1/auth.py +++ b/api/v1/auth.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText -from fastapi import APIRouter, HTTPException, status, Body +from fastapi import APIRouter, Depends, HTTPException, status, Body from fastapi.responses import JSONResponse from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm from sqlalchemy import update, select @@ -31,7 +31,7 @@ async def signup(user: UserCreate): return await UserService.create_user(user, db) @router.post("/token", response_model=Token, summary="Login and get access token") -async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Body(...)): +async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()): async with get_db() as db: user = await AuthService.authenticate_user(form_data.username, form_data.password, db) logger.info(f"User {form_data.username} logged in") diff --git a/services/auth_service.py b/services/auth_service.py index 9d01978..8372dbb 100644 --- a/services/auth_service.py +++ b/services/auth_service.py @@ -120,9 +120,6 @@ class AuthService: role_result = await db.execute(role_query) role_data = role_result.mappings().all() - if not role_data: - raise credentials_exception - role = { "id": role_data[0]["id"], "name": role_data[0]["name"],