feat: Update endpoint login

This commit is contained in:
Backend IM Bot 2025-03-11 09:32:38 +00:00
parent b92e35db55
commit 15fa58b50b

View File

@ -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}
@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