13 lines
458 B
Python
13 lines
458 B
Python
from fastapi import APIRouter, HTTPException, status
|
|
from schemas.user import UserCreate
|
|
from helpers.user_helpers import authenticate_user
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/login", status_code=status.HTTP_200_OK)
|
|
async def login(user_data: UserCreate):
|
|
"""Authenticate user"""
|
|
user = authenticate_user(user_data)
|
|
if not user:
|
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials")
|
|
return user |