diff --git a/app/api/endpoints/login.py b/app/api/endpoints/login.py index 6ed4dac..90080ca 100644 --- a/app/api/endpoints/login.py +++ b/app/api/endpoints/login.py @@ -1,7 +1,24 @@ -from fastapi import APIRouter +from fastapi import APIRouter, Depends, HTTPException, status +from fastapi.security import OAuth2PasswordBearer +from sqlalchemy.orm import Session +from typing import Union + +from models import User +from database import get_db +from auth import get_current_user router = APIRouter() +oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/login") -@router.post("/login") -async def login(username: str, password: str): - return {"message": "User logged in successfully", "username": username} \ No newline at end of file +@router.post("/logout", status_code=status.HTTP_204_NO_CONTENT) +async def logout(current_user: Union[User, None] = Depends(get_current_user), db: Session = Depends(get_db)): + """ + Logout the current user. + """ + if not current_user: + raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Not authenticated") + + # Invalidate the user's token or session + # Implementation details will depend on your authentication mechanism + + return \ No newline at end of file