From 152b45de1ff7560880cd309b849f8eca056f02c1 Mon Sep 17 00:00:00 2001 From: seeleng Date: Sat, 21 Sep 2024 21:46:12 +0800 Subject: [PATCH] feat(backend): add logout route --- backend/src/auth/router.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/src/auth/router.py b/backend/src/auth/router.py index e210528c..b3f06401 100644 --- a/backend/src/auth/router.py +++ b/backend/src/auth/router.py @@ -12,6 +12,7 @@ GOOGLE_CLIENT_SECRET, GOOGLE_REDIRECT_URI, ) +from src.auth.schemas import Token from src.common.dependencies import get_session from .schemas import SignUpData, UserPublic @@ -51,7 +52,7 @@ def sign_up(data: SignUpData, session=Depends(get_session)): @router.post("/login") def log_in( form_data: Annotated[OAuth2PasswordRequestForm, Depends()], response: Response -): +) -> Token: user = authenticate_user(form_data.username, form_data.password) if not user: raise HTTPException( @@ -122,3 +123,9 @@ def auth_google( @router.get("/session") def get_user(staff: Annotated[User, Depends(get_current_user)]) -> UserPublic: return staff + + +@router.get("/logout") +def logout(response: Response): + response.delete_cookie(key="session") + return ""