delete session

This commit is contained in:
Diogo Sousa
2023-02-01 10:47:44 +00:00
parent aaf0ea25ed
commit 01f7aa0d18
2 changed files with 9 additions and 4 deletions

View File

@@ -48,12 +48,17 @@ def create_session(
def delete_session(
base_url: str = BASE_URL, timeout: int = TIMEOUT
auth_header: str, token: str, base_url: str = BASE_URL, timeout: int = TIMEOUT
) -> Optional[requests.Response]:
"""Delete the session.
Parameters
----------
auth_header : str
The authorization header, e.g. "Bearer <token>".
token : str
The token to delete.
In the terminal we want to delete the current session, so we use the user own token.
base_url : str
The base url, by default BASE_URL
timeout : int
@@ -67,8 +72,8 @@ def delete_session(
try:
response = requests.post(
url=base_url + "logout",
headers={"Authorization": User.get_auth_header()},
json={"token": User.get_token()},
headers={"Authorization": auth_header},
json={"token": token},
timeout=timeout,
)
if response.status_code != 200:

View File

@@ -72,7 +72,7 @@ def logout(cls: bool = False):
success = True
if not User.is_guest():
r = Hub.delete_session()
r = Hub.delete_session(auth_header=User.get_auth_header(), token=User.get_token())
if r and r.status_code != 200:
success = False
User.clear()