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

Commit 2406d7d

Browse files
authored
feat: add anonymous sign in
2 parents 98006ed + ad2179b commit 2406d7d

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

infra/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ services:
106106
- '9000:9000' # web interface
107107
- '1100:1100' # POP3
108108
db:
109-
image: supabase/postgres:latest
109+
image: supabase/postgres:15.1.1.66
110110
ports:
111111
- '5432:5432'
112112
command: postgres -c config_file=/etc/postgresql/postgresql.conf

supabase_auth/_async/gotrue_client.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@
6161
Options,
6262
Provider,
6363
Session,
64+
SignInAnonymouslyCredentials,
6465
SignInWithOAuthCredentials,
6566
SignInWithPasswordCredentials,
6667
SignInWithPasswordlessCredentials,
68+
SignInWithSSOCredentials,
6769
SignOutOptions,
6870
SignUpWithPasswordCredentials,
6971
Subscription,
@@ -149,6 +151,34 @@ async def initialize_from_url(self, url: str) -> None:
149151

150152
# Public methods
151153

154+
async def sign_in_anonymously(
155+
self, credentials: Union[SignInAnonymouslyCredentials, None] = None
156+
) -> AuthResponse:
157+
"""
158+
Creates a new anonymous user.
159+
"""
160+
self._remove_session()
161+
if credentials is None:
162+
credentials = {"options": {}}
163+
options = credentials.get("options", {})
164+
data = options.get("data") or {}
165+
captcha_token = options.get("captcha_token")
166+
response = self._request(
167+
"POST",
168+
"signup",
169+
body={
170+
"data": data,
171+
"gotrue_meta_security": {
172+
"captcha_token": captcha_token,
173+
},
174+
},
175+
xform=parse_auth_response,
176+
)
177+
if response.session:
178+
self._save_session(response.session)
179+
self._notify_all_subscribers("SIGNED_IN", response.session)
180+
return response
181+
152182
async def sign_up(
153183
self,
154184
credentials: SignUpWithPasswordCredentials,

supabase_auth/_sync/gotrue_client.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@
6161
Options,
6262
Provider,
6363
Session,
64+
SignInAnonymouslyCredentials,
6465
SignInWithOAuthCredentials,
6566
SignInWithPasswordCredentials,
6667
SignInWithPasswordlessCredentials,
68+
SignInWithSSOCredentials,
6769
SignOutOptions,
6870
SignUpWithPasswordCredentials,
6971
Subscription,
@@ -149,6 +151,34 @@ def initialize_from_url(self, url: str) -> None:
149151

150152
# Public methods
151153

154+
def sign_in_anonymously(
155+
self, credentials: Union[SignInAnonymouslyCredentials, None] = None
156+
) -> AuthResponse:
157+
"""
158+
Creates a new anonymous user.
159+
"""
160+
self._remove_session()
161+
if credentials is None:
162+
credentials = {"options": {}}
163+
options = credentials.get("options", {})
164+
data = options.get("data") or {}
165+
captcha_token = options.get("captcha_token")
166+
response = self._request(
167+
"POST",
168+
"signup",
169+
body={
170+
"data": data,
171+
"gotrue_meta_security": {
172+
"captcha_token": captcha_token,
173+
},
174+
},
175+
xform=parse_auth_response,
176+
)
177+
if response.session:
178+
self._save_session(response.session)
179+
self._notify_all_subscribers("SIGNED_IN", response.session)
180+
return response
181+
152182
def sign_up(
153183
self,
154184
credentials: SignUpWithPasswordCredentials,

supabase_auth/types.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,15 @@ class SignInWithSSOOptions(TypedDict):
348348
skip_http_redirect: NotRequired[bool]
349349

350350

351+
class SignInAnonymouslyCredentials(TypedDict):
352+
options: NotRequired[SignInAnonymouslyCredentialsOptions]
353+
354+
355+
class SignInAnonymouslyCredentialsOptions(TypedDict):
356+
data: NotRequired[Any]
357+
captcha_token: NotRequired[str]
358+
359+
351360
class VerifyOtpParamsOptions(TypedDict):
352361
redirect_to: NotRequired[str]
353362
captcha_token: NotRequired[str]

0 commit comments

Comments
 (0)