2025-03-11 09:32:38 +00:00

24 lines
816 B
Python

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("/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