Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion gotrue/_async/gotrue_admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
GenerateLinkParams,
GenerateLinkResponse,
Options,
SignOutScope,
User,
UserResponse,
)
Expand All @@ -39,13 +40,14 @@ def __init__(
self.mfa.list_factors = self._list_factors
self.mfa.delete_factor = self._delete_factor

async def sign_out(self, jwt: str) -> None:
async def sign_out(self, jwt: str, scope: SignOutScope = "global") -> None:
"""
Removes a logged-in session.
"""
return await self._request(
"POST",
"logout",
query={"scope": scope},
jwt=jwt,
no_resolve_json=True,
)
Expand Down
10 changes: 6 additions & 4 deletions gotrue/_async/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
SignInWithOAuthCredentials,
SignInWithPasswordCredentials,
SignInWithPasswordlessCredentials,
SignOutOptions,
SignUpWithPasswordCredentials,
Subscription,
UserAttributes,
Expand Down Expand Up @@ -480,7 +481,7 @@ async def refresh_session(
session = await self._call_refresh_token(refresh_token)
return AuthResponse(session=session, user=session.user)

async def sign_out(self) -> None:
async def sign_out(self, options: SignOutOptions = {"scope": "global"}) -> None:
"""
Inside a browser context, `sign_out` will remove the logged in user from the
browser session and log them out - removing all items from localstorage and
Expand All @@ -496,10 +497,11 @@ async def sign_out(self) -> None:
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.admin.sign_out(access_token, options["scope"])

await self._remove_session()
self._notify_all_subscribers("SIGNED_OUT", None)
if options["scope"] != "others":
await self._remove_session()
self._notify_all_subscribers("SIGNED_OUT", None)

def on_auth_state_change(
self,
Expand Down
4 changes: 3 additions & 1 deletion gotrue/_sync/gotrue_admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
GenerateLinkParams,
GenerateLinkResponse,
Options,
SignOutScope,
User,
UserResponse,
)
Expand All @@ -39,13 +40,14 @@ def __init__(
self.mfa.list_factors = self._list_factors
self.mfa.delete_factor = self._delete_factor

def sign_out(self, jwt: str) -> None:
def sign_out(self, jwt: str, scope: SignOutScope = "global") -> None:
"""
Removes a logged-in session.
"""
return self._request(
"POST",
"logout",
query={"scope": scope},
jwt=jwt,
no_resolve_json=True,
)
Expand Down
10 changes: 6 additions & 4 deletions gotrue/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
SignInWithOAuthCredentials,
SignInWithPasswordCredentials,
SignInWithPasswordlessCredentials,
SignOutOptions,
SignUpWithPasswordCredentials,
Subscription,
UserAttributes,
Expand Down Expand Up @@ -478,7 +479,7 @@ def refresh_session(self, refresh_token: Union[str, None] = None) -> AuthRespons
session = self._call_refresh_token(refresh_token)
return AuthResponse(session=session, user=session.user)

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

self._remove_session()
self._notify_all_subscribers("SIGNED_OUT", None)
if options["scope"] != "others":
self._remove_session()
self._notify_all_subscribers("SIGNED_OUT", None)

def on_auth_state_change(
self,
Expand Down
7 changes: 7 additions & 0 deletions gotrue/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,13 @@ class DecodedJWTDict(TypedDict):
amr: NotRequired[Union[List[AMREntry], None]]


SignOutScope = Literal["global", "local", "others"]


class SignOutOptions(TypedDict):
scope: NotRequired[SignOutScope]


for model in [
AMREntry,
AuthResponse,
Expand Down