Skip to content

Commit

Permalink
logout route deleting cookie fix (#7886)
Browse files Browse the repository at this point in the history
* logout button now deletes cookies by calling RedirectResponse before deleting cookies

* add changeset

* response

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
  • Loading branch information
3 people committed Mar 29, 2024
1 parent 946487c commit ccdab9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-towns-mate.md
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:logout route deleting cookie fix
7 changes: 4 additions & 3 deletions gradio/routes.py
Expand Up @@ -37,7 +37,7 @@
import httpx
import markupsafe
import orjson
from fastapi import BackgroundTasks, Depends, FastAPI, HTTPException, Response, status
from fastapi import BackgroundTasks, Depends, FastAPI, HTTPException, status
from fastapi.responses import (
FileResponse,
HTMLResponse,
Expand Down Expand Up @@ -331,7 +331,8 @@ def login(form_data: OAuth2PasswordRequestForm = Depends()):
else:

@app.get("/logout")
def logout(response: Response, user: str = Depends(get_current_user)):
def logout(user: str = Depends(get_current_user)):
response = RedirectResponse(url="/", status_code=status.HTTP_302_FOUND)
response.delete_cookie(key=f"access-token-{app.cookie_id}", path="/")
response.delete_cookie(
key=f"access-token-unsecure-{app.cookie_id}", path="/"
Expand All @@ -340,7 +341,7 @@ def logout(response: Response, user: str = Depends(get_current_user)):
for token in list(app.tokens.keys()):
if app.tokens[token] == user:
del app.tokens[token]
return RedirectResponse(url="/", status_code=status.HTTP_302_FOUND)
return response

###############
# Main Routes
Expand Down

0 comments on commit ccdab9b

Please sign in to comment.