Skip to content

Commit

Permalink
fix: add AuthOtpResponse (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 authored Feb 9, 2024
2 parents f03e518 + 97c4713 commit 130bdb1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
8 changes: 5 additions & 3 deletions gotrue/_async/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
model_dump,
model_dump_json,
model_validate,
parse_auth_otp_response,
parse_auth_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 @@ async def unlink_identity(self, identity):
async 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 @@ async def sign_in_with_otp(
},
},
redirect_to=email_redirect_to,
xform=parse_auth_response,
xform=parse_auth_otp_response,
)
if phone:
return await self._request(
Expand All @@ -413,7 +415,7 @@ async 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
8 changes: 5 additions & 3 deletions gotrue/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
model_dump,
model_dump_json,
model_validate,
parse_auth_otp_response,
parse_auth_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
5 changes: 5 additions & 0 deletions gotrue/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from .errors import AuthApiError, AuthError, AuthRetryableError, AuthUnknownError
from .types import (
AuthOtpResponse,
AuthResponse,
GenerateLinkProperties,
GenerateLinkResponse,
Expand Down Expand Up @@ -72,6 +73,10 @@ def parse_auth_response(data: Any) -> AuthResponse:
return AuthResponse(session=session, user=user)


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


def parse_link_response(data: Any) -> GenerateLinkResponse:
properties = GenerateLinkProperties(
action_link=data.get("action_link"),
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 130bdb1

Please sign in to comment.