diff --git a/endpoints/login.post.py b/endpoints/login.post.py index c56b149..14a3261 100644 --- a/endpoints/login.post.py +++ b/endpoints/login.post.py @@ -1,16 +1,13 @@ -from fastapi import APIRouter, HTTPException, status -from typing import Dict, Any -from helpers.generic_helpers import login_user +from fastapi import APIRouter, status, HTTPException +from schemas.user import UserLogin +from helpers.auth_helpers import login_user router = APIRouter() -@router.post("/login", status_code=status.HTTP_200_OK, response_model=Dict[str, Any]) -async def login( - user_data: Dict[str, Any] -): - """Login user""" - try: - login_response = login_user(user_data=user_data) - return login_response - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) \ No newline at end of file +@router.post("/login", status_code=status.HTTP_200_OK, response_model=UserLogin) +async def login(user_data: UserLogin): + """Authenticate user and retrieve login data""" + user = login_user(user_data=user_data) + if not user: + raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials") + return user \ No newline at end of file