Skip to content
Closed
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
2 changes: 1 addition & 1 deletion sdk-compliance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ features:
- SyncMemoryStorage.set_item
client.session_management.persist_session:
status: implemented
note: "The supabase client keeps the session in memory unless session_storage is set on AuthClientOptions. The auth client constructors take persist_session: when False, the session and the PKCE code verifier stay in memory and the storage passed in is not used. They also take a storage_key to keep clients that share a storage backend apart."
note: "The supabase client keeps the session in memory unless session_storage is set on AuthClientOptions. The auth client constructors take persist_session: when False, the session and the PKCE code verifier stay in memory and the storage passed in is not used. storage_key on AuthClientOptions and the auth client constructors keeps clients that share a storage backend apart."
symbols:
- AuthClientOptions
- AsyncSupabaseAuthClient
Expand Down
2 changes: 2 additions & 0 deletions src/supabase/src/supabase/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ def auth(self) -> AsyncSupabaseAuthClient:
headers=self._headers,
auto_refresh_token=self._auth_options.auto_refresh_token,
storage=self._auth_options.session_storage,
storage_key=self._auth_options.storage_key,
flow_type=self._auth_options.flow_type,
request_timeout=self._timeout_for(self._auth_options),
)
Expand Down Expand Up @@ -647,6 +648,7 @@ def auth(self) -> SyncSupabaseAuthClient:
headers=self._headers,
auto_refresh_token=self._auth_options.auto_refresh_token,
storage=self._auth_options.session_storage,
storage_key=self._auth_options.storage_key,
flow_type=self._auth_options.flow_type,
request_timeout=self._timeout_for(self._auth_options),
)
Expand Down
4 changes: 4 additions & 0 deletions src/supabase/src/supabase/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
validate_heartbeat,
)
from supabase_auth import AsyncSupportedStorage, AuthFlowType, SyncSupportedStorage
from supabase_auth.constants import STORAGE_KEY
from supabase_utils.http.request import validate_request_timeout


Expand Down Expand Up @@ -58,6 +59,9 @@ class AuthClientOptions[Storage: (AsyncSupportedStorage, SyncSupportedStorage)](
session_storage: Storage | None = None
"""Where the logged in session is stored. None (the default) keeps it in memory."""

storage_key: str = STORAGE_KEY
"""The key the session is stored under in `session_storage`. Give clients that share a `session_storage` different keys so they do not overwrite each other's session."""

flow_type: AuthFlowType = "pkce"
"""The flow type to use for authentication."""

Expand Down
6 changes: 6 additions & 0 deletions src/supabase/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
SyncMemoryStorage,
SyncSupabaseAuthClient,
)
from supabase_auth.constants import STORAGE_KEY
from supabase_utils.http.adapters.httpx import AsyncHttpxSession, HttpxSession

import supabase.aiohttp
Expand Down Expand Up @@ -344,11 +345,13 @@ def test_sync_client_passes_service_options_to_sub_clients() -> None:
auth=AuthClientOptions(
auto_refresh_token=False,
session_storage=session_storage,
storage_key="custom-key",
flow_type="implicit",
),
)
assert client.postgrest.default_headers.get("Accept-Profile") == "private"
assert client.auth.session_manager.storage is session_storage
assert client.auth.session_manager.storage_key == "custom-key"
assert client.auth.session_manager.auto_refresh_token is False
assert client.auth.flow_type == "implicit"

Expand All @@ -364,11 +367,13 @@ async def test_async_client_passes_service_options_to_sub_clients() -> None:
auth=AuthClientOptions(
auto_refresh_token=False,
session_storage=session_storage,
storage_key="custom-key",
flow_type="implicit",
),
)
assert client.postgrest.default_headers.get("Accept-Profile") == "private"
assert client.auth.session_manager.storage is session_storage
assert client.auth.session_manager.storage_key == "custom-key"
assert client.auth.session_manager.auto_refresh_token is False
assert client.auth.flow_type == "implicit"

Expand All @@ -378,6 +383,7 @@ def test_sync_client_uses_service_defaults() -> None:
client = Client(URL, KEY, HttpxSession(client=http_client))
assert client.postgrest.default_headers.get("Accept-Profile") == "public"
assert isinstance(client.auth.session_manager.storage, SyncMemoryStorage)
assert client.auth.session_manager.storage_key == STORAGE_KEY
assert client.auth.session_manager.auto_refresh_token is True
assert client.auth.flow_type == "pkce"

Expand Down
Loading