Skip to content

Commit

Permalink
feat: add pydantic type
Browse files Browse the repository at this point in the history
  • Loading branch information
joel authored and joel committed Jan 28, 2024
1 parent 2de717a commit 1308119
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
11 changes: 7 additions & 4 deletions gotrue/_async/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
AuthResponse,
CodeExchangeParams,
DecodedJWTDict,
IdentitiesResponse,
MFAChallengeAndVerifyParams,
MFAChallengeParams,
MFAEnrollParams,
Expand Down Expand Up @@ -291,14 +292,16 @@ async def link_identity(self, credentials):

async def get_user_identities(self):
response = self.get_user()
user = response.get("user")
identities = user.get("identities", []) if user else []
return {"data": {"identities": identities}}
return (
IdentitiesResponse(identities=response.user.identities)
if response.user
else AuthSessionMissingError()
)

async def unlink_identity(self, identity):
return await self._request(
"POST",
f"/user/identities/{identity.identity_id}",
f"/user/identities/{identity.id}",
)

async def sign_in_with_otp(
Expand Down
11 changes: 7 additions & 4 deletions gotrue/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
AuthResponse,
CodeExchangeParams,
DecodedJWTDict,
IdentitiesResponse,
MFAChallengeAndVerifyParams,
MFAChallengeParams,
MFAEnrollParams,
Expand Down Expand Up @@ -291,14 +292,16 @@ def link_identity(self, credentials):

def get_user_identities(self):
response = self.get_user()
user = response.get("user")
identities = user.get("identities", []) if user else []
return {"data": {"identities": identities}}
return (
IdentitiesResponse(identities=response.user.identities)
if response.user
else AuthSessionMissingError()
)

def unlink_identity(self, identity):
return self._request(
"POST",
f"/user/identities/{identity.identity_id}",
f"/user/identities/{identity.id}",
)

def sign_in_with_otp(
Expand Down
19 changes: 19 additions & 0 deletions gotrue/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ class OAuthResponse(BaseModel):
url: str


class SSOResponse(BaseModel):
url: str


class IdentitiesResponse(BaseModel):
identities: List[UserIdentity]


class UserResponse(BaseModel):
user: User

Expand Down Expand Up @@ -323,6 +331,17 @@ class SignInWithOAuthCredentials(TypedDict):
options: NotRequired[SignInWithOAuthCredentialsOptions]


class SignInWithSSOCredentials(TypedDict):
provider_id: NotRequired[str]
domain: NotRequired[str]
options: NotRequired[SignInWithSSOOptions]


class SignInWithSSOOptions(TypedDict):
redirect_to: NotRequired[str]
skip_http_redirect: NotRequired[bool]


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

0 comments on commit 1308119

Please sign in to comment.