diff --git a/endpoints/login.post.py b/endpoints/login.post.py index a63ef50..6ebacb0 100644 --- a/endpoints/login.post.py +++ b/endpoints/login.post.py @@ -2,22 +2,27 @@ from fastapi import APIRouter, Depends, HTTPException, status from sqlalchemy.orm import Session from core.database import get_db from models.user import User -from schemas.user import UserLogin, TokenResponse +from schemas.user import UserLogin, UserResponse from helpers.auth_helpers import authenticate_user, create_access_token router = APIRouter() -@router.post("/login", status_code=200, response_model=TokenResponse) +@router.post("/login", status_code=200, response_model=UserResponse) async def login( login_data: UserLogin, db: Session = Depends(get_db) ): - user = authenticate_user(db, login_data.email, login_data.password) + user = authenticate_user(db, login_data.username, login_data.password) if not user: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, - detail="Incorrect email or password", + detail="Incorrect username or password", headers={"WWW-Authenticate": "Bearer"}, ) - access_token = create_access_token(data={"sub": user.email}) - return {"access_token": access_token, "token_type": "bearer"} \ No newline at end of file + + access_token = create_access_token(data={"sub": user.username}) + return { + "access_token": access_token, + "token_type": "bearer", + "user": user + } \ No newline at end of file