Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
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
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (llm): Switching the transformation function to parse_auth_otp_response for OTP sign-ins is a logical step following the introduction of AuthOtpResponse. This change ensures that the response parsing is aligned with the expected response structure. It's a good practice to verify that the transformation function correctly handles all possible response variations to avoid runtime errors.

)
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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (llm): Introducing AuthOtpResponse as a new response type is a good design decision for handling OTP-specific responses. However, it's important to ensure that the message_id field is adequately documented, including its purpose and any relevant constraints or expected values. This will help maintain clarity and ease of use for developers interacting with this part of the API.

user: None = None
session: None = None
message_id: Union[str, None] = None


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