-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add AuthOtpResponse #419
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Type: Enhancement
PR Summary: This pull request introduces a new response type, AuthOtpResponse
, specifically designed for handling responses from one-time password (OTP) sign-ins. It modifies the sign_in_with_otp
method in the gotrue_client.py
file to return this new type instead of the generic AuthResponse
. Additionally, it simplifies the parse_auth_response
function in helpers.py
and adds a new function parse_auth_otp_response
to parse the OTP-specific responses. The changes also include the necessary adjustments in imports and type declarations to accommodate the new AuthOtpResponse
type.
Decision: Comment
📝 Type: 'Enhancement' - not supported yet.
- Sourcery currently only approves 'Typo fix' PRs.
✅ Issue addressed: this change correctly addresses the issue or implements the desired feature.
No details provided.
✅ Small diff: the diff is small enough to approve with confidence.
No details provided.
General suggestions:
- Ensure that the
model_validate
function used in the simplifiedparse_auth_response
and the newparse_auth_otp_response
is capable of handling all necessary validations, especially for the fieldsaccess_token
,refresh_token
, andexpires_in
. This is crucial to prevent potential bugs due to missing or invalid data. - Consider adding detailed documentation for the
message_id
field in theAuthOtpResponse
class. This should include its purpose, any constraints on its value, and how it should be used by consumers of the API. Clear documentation will aid in maintaining clarity and ease of use for developers. - Verify that the new
parse_auth_otp_response
function and the change in the transformation function toparse_auth_otp_response
ingotrue_client.py
correctly handle all possible variations of the OTP response. This is important to ensure robustness and prevent runtime errors.
Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨
gotrue/helpers.py
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (llm): The refactoring to directly return model_validate(AuthResponse, data)
simplifies the code significantly. However, ensure that model_validate
is capable of handling all the previous checks and conditions, especially the presence and validity of access_token
, refresh_token
, and expires_in
. If model_validate
doesn't perform these checks, this change might introduce a bug risk by assuming all necessary fields are present and valid.
@@ -89,6 +89,12 @@ class AuthResponse(BaseModel): | |||
session: Union[Session, None] = None | |||
|
|||
|
|||
class AuthOtpResponse(BaseModel): |
There was a problem hiding this comment.
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.
@@ -399,7 +401,7 @@ def sign_in_with_otp( | |||
}, | |||
}, | |||
redirect_to=email_redirect_to, | |||
xform=parse_auth_response, | |||
xform=parse_auth_otp_response, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved changes to _async and run make build_sync
.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #419 +/- ##
==========================================
- Coverage 45.33% 44.71% -0.63%
==========================================
Files 23 23
Lines 1963 2044 +81
==========================================
+ Hits 890 914 +24
- Misses 1073 1130 +57 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
What kind of change does this PR introduce?
This PR adds a new type
AuthOtpResponse
returned whensign_in_with_otp
is called. The new type has an optional message_id. Closes #406.What is the current behavior?
#406
What is the new behavior?
AuthOtpResponse correctly parses an optional
message_id
field in the OTP response.