Skip to content

Commit

Permalink
update async client and type naming
Browse files Browse the repository at this point in the history
  • Loading branch information
silentworks committed Jun 20, 2024
1 parent f3d35c7 commit 85f94f2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 26 deletions.
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 @@ async def initialize_from_url(self, url: str) -> None:

# 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(
"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

async def sign_up(
self,
credentials: SignUpWithPasswordCredentials,
Expand Down
55 changes: 31 additions & 24 deletions supabase_auth/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@
Options,
Provider,
Session,
SignInAnonymouslyCredentials,
SignInWithOAuthCredentials,
SignInWithPasswordCredentials,
SignInWithPasswordlessCredentials,
SignInWithSSOCredentials,
SignOutOptions,
SignUpWithPasswordCredentials,
Subscription,
UserAttributes,
UserResponse,
VerifyOtpParams, SignInAnonymouslyCredentials,
VerifyOtpParams,
)
from .gotrue_admin_api import SyncGoTrueAdminAPI
from .gotrue_base_api import SyncGoTrueBaseAPI
Expand Down Expand Up @@ -149,6 +151,34 @@ def initialize_from_url(self, url: str) -> None:

# 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(
"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

def sign_up(
self,
credentials: SignUpWithPasswordCredentials,
Expand Down Expand Up @@ -337,29 +367,6 @@ def sign_in_with_oauth(
url = self._get_url_for_provider(provider, params)
return OAuthResponse(provider=provider, url=url)

def sign_in_anonymously(self, credentials: Union[SignInAnonymouslyCredentials]) -> AuthResponse:
"""
Creates a new anonymous user.
"""
self._remove_session()
options = credentials.get("options", {})
data = options.get("data") or {}
captcha_token = options.get("captcha_token")
response = self._request(
"POST",
"signup",
body={
"data": data,
"gotrue_meta_security": {
"captcha_token": captcha_token,
},
}
)
if response.session:
self._save_session(response.session)
self._notify_all_subscribers("SIGNED_IN", response.session)
return response

def link_identity(self, credentials):
provider = credentials.get("provider")
options = credentials.get("options", {})
Expand Down
4 changes: 2 additions & 2 deletions supabase_auth/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ class SignInWithSSOOptions(TypedDict):


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


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

Expand Down

0 comments on commit 85f94f2

Please sign in to comment.