Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 3818dba

Browse files
committed
feat: add sign_out() scope option
1 parent 1440dd6 commit 3818dba

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

gotrue/_async/gotrue_admin_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
GenerateLinkParams,
1515
GenerateLinkResponse,
1616
Options,
17+
SignOutScope,
1718
User,
1819
UserResponse,
1920
)
@@ -39,13 +40,13 @@ def __init__(
3940
self.mfa.list_factors = self._list_factors
4041
self.mfa.delete_factor = self._delete_factor
4142

42-
async def sign_out(self, jwt: str) -> None:
43+
async def sign_out(self, jwt: str, scope: SignOutScope = "global") -> None:
4344
"""
4445
Removes a logged-in session.
4546
"""
4647
return await self._request(
4748
"POST",
48-
"logout",
49+
f"logout?scope={scope}",
4950
jwt=jwt,
5051
no_resolve_json=True,
5152
)

gotrue/_async/gotrue_client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
SignInWithOAuthCredentials,
6161
SignInWithPasswordCredentials,
6262
SignInWithPasswordlessCredentials,
63+
SignOutOptions,
6364
SignUpWithPasswordCredentials,
6465
Subscription,
6566
UserAttributes,
@@ -480,7 +481,7 @@ async def refresh_session(
480481
session = await self._call_refresh_token(refresh_token)
481482
return AuthResponse(session=session, user=session.user)
482483

483-
async def sign_out(self) -> None:
484+
async def sign_out(self, options: SignOutOptions = {"scope": "global"}) -> None:
484485
"""
485486
Inside a browser context, `sign_out` will remove the logged in user from the
486487
browser session and log them out - removing all items from localstorage and
@@ -496,10 +497,11 @@ async def sign_out(self) -> None:
496497
session = await self.get_session()
497498
access_token = session.access_token if session else None
498499
if access_token:
499-
await self.admin.sign_out(access_token)
500+
await self.admin.sign_out(access_token, options["scope"])
500501

501-
await self._remove_session()
502-
self._notify_all_subscribers("SIGNED_OUT", None)
502+
if options["scope"] != "others":
503+
await self._remove_session()
504+
self._notify_all_subscribers("SIGNED_OUT", None)
503505

504506
def on_auth_state_change(
505507
self,

gotrue/_sync/gotrue_admin_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
GenerateLinkParams,
1515
GenerateLinkResponse,
1616
Options,
17+
SignOutScope,
1718
User,
1819
UserResponse,
1920
)
@@ -39,13 +40,13 @@ def __init__(
3940
self.mfa.list_factors = self._list_factors
4041
self.mfa.delete_factor = self._delete_factor
4142

42-
def sign_out(self, jwt: str) -> None:
43+
def sign_out(self, jwt: str, scope: SignOutScope = "global") -> None:
4344
"""
4445
Removes a logged-in session.
4546
"""
4647
return self._request(
4748
"POST",
48-
"logout",
49+
f"logout?scope={scope}",
4950
jwt=jwt,
5051
no_resolve_json=True,
5152
)

gotrue/_sync/gotrue_client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
SignInWithOAuthCredentials,
6161
SignInWithPasswordCredentials,
6262
SignInWithPasswordlessCredentials,
63+
SignOutOptions,
6364
SignUpWithPasswordCredentials,
6465
Subscription,
6566
UserAttributes,
@@ -478,7 +479,7 @@ def refresh_session(self, refresh_token: Union[str, None] = None) -> AuthRespons
478479
session = self._call_refresh_token(refresh_token)
479480
return AuthResponse(session=session, user=session.user)
480481

481-
def sign_out(self) -> None:
482+
def sign_out(self, options: SignOutOptions = {"scope": "global"}) -> None:
482483
"""
483484
Inside a browser context, `sign_out` will remove the logged in user from the
484485
browser session and log them out - removing all items from localstorage and
@@ -494,10 +495,11 @@ def sign_out(self) -> None:
494495
session = self.get_session()
495496
access_token = session.access_token if session else None
496497
if access_token:
497-
self.admin.sign_out(access_token)
498+
self.admin.sign_out(access_token, options["scope"])
498499

499-
self._remove_session()
500-
self._notify_all_subscribers("SIGNED_OUT", None)
500+
if options["scope"] != "others":
501+
self._remove_session()
502+
self._notify_all_subscribers("SIGNED_OUT", None)
501503

502504
def on_auth_state_change(
503505
self,

gotrue/types.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,13 @@ class DecodedJWTDict(TypedDict):
650650
amr: NotRequired[Union[List[AMREntry], None]]
651651

652652

653+
SignOutScope = Literal["global", "local", "others"]
654+
655+
656+
class SignOutOptions(TypedDict):
657+
scope: NotRequired[SignOutScope]
658+
659+
653660
for model in [
654661
AMREntry,
655662
AuthResponse,

0 commit comments

Comments
 (0)