Skip to content

Commit

Permalink
Merge pull request #342 from supabase-community/silentworks/sign-out-…
Browse files Browse the repository at this point in the history
…exception-handling

feat: Add exception to handle API errors on signout
  • Loading branch information
Andrew Smith authored Oct 5, 2023
2 parents 5155312 + 2d964ad commit 708859c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions gotrue/_async/gotrue_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from contextlib import suppress
from functools import partial
from json import loads
from time import time
Expand All @@ -16,6 +17,7 @@
STORAGE_KEY,
)
from ..errors import (
AuthApiError,
AuthImplicitGrantRedirectError,
AuthInvalidCredentialsError,
AuthRetryableError,
Expand Down Expand Up @@ -483,10 +485,12 @@ async def sign_out(self) -> None:
There is no way to revoke a user's access token jwt until it expires.
It is recommended to set a shorter expiry on the jwt for this reason.
"""
session = await self.get_session()
access_token = session.access_token if session else None
if access_token:
await self.admin.sign_out(access_token)
with suppress(AuthApiError):
session = await self.get_session()
access_token = session.access_token if session else None
if access_token:
await self.admin.sign_out(access_token)

await self._remove_session()
self._notify_all_subscribers("SIGNED_OUT", None)

Expand Down
12 changes: 8 additions & 4 deletions gotrue/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from contextlib import suppress
from functools import partial
from json import loads
from time import time
Expand All @@ -16,6 +17,7 @@
STORAGE_KEY,
)
from ..errors import (
AuthApiError,
AuthImplicitGrantRedirectError,
AuthInvalidCredentialsError,
AuthRetryableError,
Expand Down Expand Up @@ -481,10 +483,12 @@ def sign_out(self) -> None:
There is no way to revoke a user's access token jwt until it expires.
It is recommended to set a shorter expiry on the jwt for this reason.
"""
session = self.get_session()
access_token = session.access_token if session else None
if access_token:
self.admin.sign_out(access_token)
with suppress(AuthApiError):
session = self.get_session()
access_token = session.access_token if session else None
if access_token:
self.admin.sign_out(access_token)

self._remove_session()
self._notify_all_subscribers("SIGNED_OUT", None)

Expand Down

0 comments on commit 708859c

Please sign in to comment.