Skip to content

Commit

Permalink
fix: add AuthOtpResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
abyesilyurt committed Feb 6, 2024
1 parent 640d0c1 commit 8d64ca4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 5 additions & 3 deletions gotrue/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
model_dump_json,
model_validate,
parse_auth_response,
parse_auth_otp_response,
parse_sso_response,
parse_user_response,
)
Expand All @@ -46,6 +47,7 @@
AuthMFAListFactorsResponse,
AuthMFAUnenrollResponse,
AuthMFAVerifyResponse,
AuthOtpResponse,
AuthResponse,
CodeExchangeParams,
DecodedJWTDict,
Expand Down Expand Up @@ -365,7 +367,7 @@ def unlink_identity(self, identity):
def sign_in_with_otp(
self,
credentials: SignInWithPasswordlessCredentials,
) -> AuthResponse:
) -> AuthOtpResponse:
"""
Log in a user using magiclink or a one-time password (OTP).
Expand Down Expand Up @@ -399,7 +401,7 @@ def sign_in_with_otp(
},
},
redirect_to=email_redirect_to,
xform=parse_auth_response,
xform=parse_auth_otp_response,
)
if phone:
return self._request(
Expand All @@ -413,7 +415,7 @@ def sign_in_with_otp(
"captcha_token": captcha_token,
},
},
xform=parse_auth_response,
xform=parse_auth_otp_response,
)
raise AuthInvalidCredentialsError(
"You must provide either an email or phone number"
Expand Down
20 changes: 6 additions & 14 deletions gotrue/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from .errors import AuthApiError, AuthError, AuthRetryableError, AuthUnknownError
from .types import (
AuthResponse,
AuthOtpResponse,
GenerateLinkProperties,
GenerateLinkResponse,
Session,
SSOResponse,
User,
UserResponse,
Expand Down Expand Up @@ -57,19 +57,11 @@ def model_dump_json(model: BaseModel) -> str:


def parse_auth_response(data: Any) -> AuthResponse:
session: Union[Session, None] = None
if (
"access_token" in data
and "refresh_token" in data
and "expires_in" in data
and data["access_token"]
and data["refresh_token"]
and data["expires_in"]
):
session = model_validate(Session, data)
user_data = data.get("user", data)
user = model_validate(User, user_data) if user_data else None
return AuthResponse(session=session, user=user)
return model_validate(AuthResponse, data)


def parse_auth_otp_response(data: Any) -> AuthOtpResponse:
return model_validate(AuthOtpResponse, data)


def parse_link_response(data: Any) -> GenerateLinkResponse:
Expand Down
6 changes: 6 additions & 0 deletions gotrue/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class AuthResponse(BaseModel):
session: Union[Session, None] = None


class AuthOtpResponse(BaseModel):
user: None = None
session: None = None
message_id: Union[str, None] = None


class OAuthResponse(BaseModel):
provider: Provider
url: str
Expand Down

0 comments on commit 8d64ca4

Please # to comment.