Skip to content

Commit

Permalink
feat: add logout endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
anand2312 committed Nov 25, 2023
1 parent e19318a commit 290a0fa
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions quill_server/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession

from quill_server.auth import get_current_user, hash_password, set_session, verify_password
from quill_server.auth import (
delete_session,
get_current_session,
hash_password,
set_session,
verify_password,
)
from quill_server.auth.session import Session
from quill_server.db.connect import get_db
from quill_server.db.models import User
from quill_server.schema import MessageResponse, SuccessfulLoginResponse, UserSignupBody
Expand Down Expand Up @@ -58,6 +65,7 @@ async def login(
return SuccessfulLoginResponse(username=username, **session.model_dump())


@router.get("/loggedin")
async def test_logged_in(user: Annotated[User, Depends(get_current_user)]) -> MessageResponse:
return MessageResponse(message=f"Hello {user.username}!")
@router.post("/logout")
async def logout(session: Annotated[Session, Depends(get_current_session)]) -> MessageResponse:
await delete_session(session.id)
return MessageResponse(message="Logged out")

0 comments on commit 290a0fa

Please sign in to comment.