File size: 604 Bytes
bfa9638
10399f1
bfa9638
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from fastapi import APIRouter, Depends, HTTPException
from ..utils.db import tinydb_helper  # Ensure this import is correct based on our project structure
from ..dependencies import oauth2_scheme

router = APIRouter()

@router.post("/user/logout")
async def user_logout(token: str = Depends(oauth2_scheme)):
    try:
        # Invalidate the token by removing it from the database
        tinydb_helper.remove_token_by_value(token)
        return {"message": "User logged out successfully"}
    except Exception as e:
        raise HTTPException(status_code=400, detail=f"Error during logout: {str(e)}")