Skip to content
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

Merged
merged 4 commits into from
Feb 9, 2024
Merged

fix: add AuthOtpResponse #419

merged 4 commits into from
Feb 9, 2024

Conversation

abyesilyurt
Copy link
Contributor

@abyesilyurt abyesilyurt commented Feb 6, 2024

What kind of change does this PR introduce?

This PR adds a new type AuthOtpResponse returned when sign_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.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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 simplified parse_auth_response and the new parse_auth_otp_response is capable of handling all necessary validations, especially for the fields access_token, refresh_token, and expires_in. This is crucial to prevent potential bugs due to missing or invalid data.
  • Consider adding detailed documentation for the message_id field in the AuthOtpResponse 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 to parse_auth_otp_response in gotrue_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? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

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

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):
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.

@@ -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.

Copy link
Contributor

@J0 J0 left a comment

Choose a reason for hiding this comment

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

Thank you!

gotrue/_sync/gotrue_client.py Show resolved Hide resolved
Copy link
Contributor Author

@abyesilyurt abyesilyurt left a 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.

gotrue/_sync/gotrue_client.py Outdated Show resolved Hide resolved
gotrue/_sync/gotrue_client.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Feb 8, 2024

Codecov Report

Attention: 56 lines in your changes are missing coverage. Please review.

Comparison is base (4ec8842) 45.33% compared to head (97c4713) 44.71%.
Report is 41 commits behind head on main.

Files Patch % Lines
gotrue/_async/gotrue_client.py 12.90% 27 Missing ⚠️
gotrue/_sync/gotrue_client.py 12.90% 27 Missing ⚠️
gotrue/helpers.py 50.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@J0 J0 left a 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!

@J0 J0 merged commit 130bdb1 into supabase:main Feb 9, 2024
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add message_id field to sign_in_with_otp
2 participants