Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add anonymous login #528

Merged
merged 3 commits into from
Jun 20, 2024
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
2 changes: 1 addition & 1 deletion infra/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ services:
- '9000:9000' # web interface
- '1100:1100' # POP3
db:
image: supabase/postgres:latest
image: supabase/postgres:15.1.1.66
ports:
- '5432:5432'
command: postgres -c config_file=/etc/postgresql/postgresql.conf
Expand Down
30 changes: 30 additions & 0 deletions supabase_auth/_async/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@
Options,
Provider,
Session,
SignInAnonymouslyCredentials,
SignInWithOAuthCredentials,
SignInWithPasswordCredentials,
SignInWithPasswordlessCredentials,
SignInWithSSOCredentials,
SignOutOptions,
SignUpWithPasswordCredentials,
Subscription,
Expand Down Expand Up @@ -149,6 +151,34 @@

# Public methods

async def sign_in_anonymously(
self, credentials: Union[SignInAnonymouslyCredentials, None] = None
) -> AuthResponse:
"""
Creates a new anonymous user.
"""
self._remove_session()
if credentials is None:
credentials = {"options": {}}
options = credentials.get("options", {})
data = options.get("data") or {}
captcha_token = options.get("captcha_token")
response = self._request(

Check warning on line 166 in supabase_auth/_async/gotrue_client.py

View check run for this annotation

Codecov / codecov/patch

supabase_auth/_async/gotrue_client.py#L160-L166

Added lines #L160 - L166 were not covered by tests
"POST",
"signup",
body={
"data": data,
"gotrue_meta_security": {
"captcha_token": captcha_token,
},
},
xform=parse_auth_response,
)
if response.session:
self._save_session(response.session)
self._notify_all_subscribers("SIGNED_IN", response.session)
return response

Check warning on line 180 in supabase_auth/_async/gotrue_client.py

View check run for this annotation

Codecov / codecov/patch

supabase_auth/_async/gotrue_client.py#L177-L180

Added lines #L177 - L180 were not covered by tests

async def sign_up(
self,
credentials: SignUpWithPasswordCredentials,
Expand Down
30 changes: 30 additions & 0 deletions supabase_auth/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@
Options,
Provider,
Session,
SignInAnonymouslyCredentials,
SignInWithOAuthCredentials,
SignInWithPasswordCredentials,
SignInWithPasswordlessCredentials,
SignInWithSSOCredentials,
SignOutOptions,
SignUpWithPasswordCredentials,
Subscription,
Expand Down Expand Up @@ -149,6 +151,34 @@

# Public methods

def sign_in_anonymously(
self, credentials: Union[SignInAnonymouslyCredentials, None] = None
) -> AuthResponse:
"""
Creates a new anonymous user.
"""
self._remove_session()
if credentials is None:
credentials = {"options": {}}
options = credentials.get("options", {})
data = options.get("data") or {}
captcha_token = options.get("captcha_token")
response = self._request(

Check warning on line 166 in supabase_auth/_sync/gotrue_client.py

View check run for this annotation

Codecov / codecov/patch

supabase_auth/_sync/gotrue_client.py#L160-L166

Added lines #L160 - L166 were not covered by tests
"POST",
"signup",
body={
"data": data,
"gotrue_meta_security": {
"captcha_token": captcha_token,
},
},
xform=parse_auth_response,
)
if response.session:
self._save_session(response.session)
self._notify_all_subscribers("SIGNED_IN", response.session)
return response

Check warning on line 180 in supabase_auth/_sync/gotrue_client.py

View check run for this annotation

Codecov / codecov/patch

supabase_auth/_sync/gotrue_client.py#L177-L180

Added lines #L177 - L180 were not covered by tests

def sign_up(
self,
credentials: SignUpWithPasswordCredentials,
Expand Down
9 changes: 9 additions & 0 deletions supabase_auth/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,15 @@ class SignInWithSSOOptions(TypedDict):
skip_http_redirect: NotRequired[bool]


class SignInAnonymouslyCredentials(TypedDict):
options: NotRequired[SignInAnonymouslyCredentialsOptions]


class SignInAnonymouslyCredentialsOptions(TypedDict):
data: NotRequired[Any]
captcha_token: NotRequired[str]


class VerifyOtpParamsOptions(TypedDict):
redirect_to: NotRequired[str]
captcha_token: NotRequired[str]
Expand Down