25 lines
654 B
Python
25 lines
654 B
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
users = [] # In-memory storage
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/logout")
|
|
async def logout_demo(
|
|
username: str = "logged_in_user"
|
|
):
|
|
"""Demo logout endpoint"""
|
|
if request.method != "POST":
|
|
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
|
|
|
user = next((u for u in users if u["username"] == username), None)
|
|
if not user:
|
|
raise HTTPException(status_code=400, detail="Invalid user")
|
|
|
|
# Perform logout logic (e.g., invalidate token)
|
|
|
|
return {
|
|
"message": "Logout successful",
|
|
"method": "POST",
|
|
"_verb": "post"
|
|
} |