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

feat: login with pair code #171

Merged
merged 11 commits into from
Jul 29, 2024
Merged

feat: login with pair code #171

merged 11 commits into from
Jul 29, 2024

Conversation

aldinokemal
Copy link
Owner

Context

  • Login with pair code without scanning QRCode

Test Results

paircode

feat(app): add LoginWithCode method to IAppService interface for handling phone number login
feat(app): implement LoginWithCode method in App struct to handle phone number login logic
feat(app): implement LoginWithCode method in serviceApp to pair phone number with WhatsApp client
Copy link
Contributor

coderabbitai bot commented Jul 14, 2024

Walkthrough

This update brings notable enhancements to the WhatsApp API MultiDevice application, primarily focusing on user authentication improvements. A new login method utilizing a pairing code has been added, enhancing usability. The API version has been updated, and various components and files have been modified to support the new functionality, including documentation, validation, and user interface elements. These changes aim to provide a more seamless user experience while ensuring dependencies are up-to-date.

Changes

Files Change Summary
docker/golang.Dockerfile Upgraded Go and Alpine base images for improved security and performance.
docs/openapi.yaml Incremented API version to 4.2.0 and added /app/login-with-code endpoint for login with a pairing code.
readme.md Replaced "Feature" table with a detailed "User Interface" table and updated login descriptions.
src/config/settings.go Updated AppVersion from "v4.15.0" to "v4.16.0".
src/domains/app/app.go Added LoginWithCode method to IAppService interface for new login functionality.
src/go.mod Updated various module dependencies for maintenance and improvements.
src/internal/rest/app.go Introduced LoginWithCode method and route for user authentication via a pairing code.
src/services/app.go Implemented LoginWithCode method for handling login logic with phone number validation.
src/validations/app_validation.go New file containing ValidateLoginWithCode function for phone number validation.
src/validations/app_validation_test.go Added unit tests for ValidateLoginWithCode function to ensure proper validation behavior.
src/views/components/AppLogin.js Added connected prop to manage user login state and prevent unnecessary modal interactions.
src/views/components/AppLoginWithCode.js New component for user login via pairing code with interactive modal interface.
src/views/components/AppReconnect.js Simplified instruction text for reconnecting to the WhatsApp service.
src/views/index.html Integrated new <app-login-with-code> component and updated existing components for improved connection state handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AppLoginWithCode
    participant Service
    participant API

    User->>AppLoginWithCode: Enter phone number
    AppLoginWithCode->>Service: Validate phone number
    Service->>API: Request login with code
    API-->>Service: Return pair code
    Service-->>AppLoginWithCode: Provide pair code
    AppLoginWithCode-->>User: Display pair code
Loading

🐰 In the meadow, hop and play,
New codes for logging in today!
With pairing joy, users can find,
A smoother path, oh so kind!
Let’s celebrate this change with cheer,
A rabbit’s dance brings us near! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@aldinokemal aldinokemal marked this pull request as ready for review July 29, 2024 14:34
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 9

Outside diff range, codebase verification and nitpick comments (4)
src/internal/rest/app.go (1)

17-17: Integration tests for the new endpoint are missing.

The new endpoint /app/login-with-code is correctly added and documented. However, there are no integration tests covering this endpoint. Please ensure that integration tests are added to verify its functionality.

  • File: src/internal/rest/app.go
  • Endpoint: /app/login-with-code
Analysis chain

Ensure the new endpoint is documented and tested.

The new endpoint /app/login-with-code is correctly added. Ensure that it is properly documented in the API documentation and covered by integration tests.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new endpoint is documented and tested.

# Test: Search for the endpoint documentation. Expect: Documentation for the new endpoint.
rg --type markdown '/app/login-with-code'

# Test: Search for the endpoint tests. Expect: Integration tests for the new endpoint.
rg --type go 'app/login-with-code'

Length of output: 248


Script:

#!/bin/bash
# Description: Verify that the new endpoint is covered by integration tests.

# Test: Search for the endpoint tests in the test directory. Expect: Integration tests for the new endpoint.
rg 'app/login-with-code' --type go --glob 'test/**'

Length of output: 200


Script:

#!/bin/bash
# Description: Verify that the new endpoint is covered by integration tests.

# Test: Search for the endpoint tests in all Go files. Expect: Integration tests for the new endpoint.
rg 'app/login-with-code' --type go

Length of output: 112

src/views/components/AppLogin.js (2)

Line range hint 25-27:
Ensure the API endpoint is correctly updated.

The API endpoint should be updated to handle the new login method with a code.

-  let response = await window.http.get(`/app/login`)
+  let response = await window.http.get(`/app/login-with-code?phone=${this.phoneNumber}`)

3-5: Ensure the new prop is documented and tested.

The new prop connected is correctly added in the code, but it lacks proper documentation and unit tests. Please ensure that the connected prop is documented in the relevant component documentation and covered by unit tests.

  • Documentation: Add details about the connected prop in the component's documentation.
  • Unit Tests: Add unit tests to cover the functionality related to the connected prop.
Analysis chain

Ensure the new prop is documented and tested.

The new prop connected is correctly added. Ensure that it is properly documented in the component documentation and covered by unit tests.


Let's correct the command to search for the connected prop documentation and tests by specifying the correct file type or using a glob pattern.


To ensure that the connected prop is documented and tested, we need to search for relevant documentation files (like README.md, component documentation files) and test files (like files in a tests directory or files following a test naming convention).


Let's list the relevant files first and then search within them to ensure the connected prop is documented and tested.


Let's search for documentation in the readme.md file and search for the connected prop in all JavaScript files to ensure we cover possible test files.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new prop is documented and tested.

# Test: Search for the prop documentation. Expect: Documentation for the new prop.
rg --type javascript 'connected'

# Test: Search for the prop tests. Expect: Unit tests for the new prop.
rg --type javascript 'connected' --files-with-matches | xargs -I {} rg 'connected' {}

Length of output: 190


Script:

#!/bin/bash
# Description: Verify that the new prop is documented and tested.

# Test: Search for the prop documentation. Expect: Documentation for the new prop.
rg --glob '*.js' 'connected'

# Test: Search for the prop tests. Expect: Unit tests for the new prop.
rg --glob '*.js' 'connected' --files-with-matches | xargs -I {} rg 'connected' {}

Length of output: 779


Script:

#!/bin/bash
# Description: Verify that the new prop is documented and tested.

# Search for documentation in markdown files
rg 'connected' --glob '*.md'

# Search for test files that include the connected prop
rg 'connected' --glob '*.{test,spec}.js'

Length of output: 218


Script:

#!/bin/bash
# Description: Verify that the new prop is documented and tested.

# List markdown files
echo "Markdown files:"
fd --type f --extension md

# List test files
echo "Test files:"
fd --type f --extension js --exec echo {} \; | grep -E '\.(test|spec)\.js$'

# Search for documentation in markdown files
echo "Searching for documentation in markdown files:"
rg 'connected' --glob '*.md'

# Search for test files that include the connected prop
echo "Searching for tests in test files:"
rg 'connected' --glob '*.{test,spec}.js'

Length of output: 594


Script:

#!/bin/bash
# Description: Verify that the new prop is documented and tested.

# Search for documentation in the readme.md file
echo "Searching for documentation in readme.md:"
rg 'connected' readme.md

# Search for the connected prop in all JavaScript files, including possible test files
echo "Searching for tests and usage in JavaScript files:"
rg 'connected' --glob '*.js'

Length of output: 685

readme.md (1)

143-143: Reduce the number of exclamation marks.

Using many exclamation marks might seem excessive. Consider reducing their usage.

- | Homepage           | ![Homepage](https://i.ibb.co.com/L0B1LVb/homepage-v4-16.png)                             |
+ | Homepage           | ![Homepage](https://i.ibb.co.com/L0B1LVb/homepage-v4-16.png)                             |
Tools
LanguageTool

[style] ~143-~143: Using many exclamation marks might seem excessive (in this case: 26 exclamation marks for a text that’s 7858 characters long)
Context: ...---------------| | Homepage | Homepage | | Login | Login | | Login With Code | Login With Code | | Send Message | Send Message | | Send Image | Send Image | | Send File | Send File | | Send Video | Send Video | | Send Contact | Send Contact | | Send Location | Send Location | | Send Audio | Send Audio | | Send Poll | Send Poll | | Revoke Message | Revoke Message | | Delete Message | Delete Message | | Reaction Message | Reaction Message | | Edit Message | Edit Message | | User Info | User Info | | User Avatar | User Avatar | | My Privacy | My Privacy | | My Group | My Group | | Auto Reply | Auto Reply | | Basic Auth Prompt | Basic Auth Prompt | | Manage Participant | ![Manage Participant](https://i.ibb.co.co...

(EN_EXCESSIVE_EXCLAMATION)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8e5b1da and 221d638.

Files ignored due to path filters (1)
  • src/go.sum is excluded by !**/*.sum
Files selected for processing (14)
  • docker/golang.Dockerfile (2 hunks)
  • docs/openapi.yaml (3 hunks)
  • readme.md (2 hunks)
  • src/config/settings.go (1 hunks)
  • src/domains/app/app.go (1 hunks)
  • src/go.mod (2 hunks)
  • src/internal/rest/app.go (2 hunks)
  • src/services/app.go (2 hunks)
  • src/validations/app_validation.go (1 hunks)
  • src/validations/app_validation_test.go (1 hunks)
  • src/views/components/AppLogin.js (3 hunks)
  • src/views/components/AppLoginWithCode.js (1 hunks)
  • src/views/components/AppReconnect.js (1 hunks)
  • src/views/index.html (3 hunks)
Files skipped from review due to trivial changes (3)
  • src/config/settings.go
  • src/go.mod
  • src/views/components/AppReconnect.js
Additional context used
LanguageTool
readme.md

[style] ~143-~143: Using many exclamation marks might seem excessive (in this case: 26 exclamation marks for a text that’s 7858 characters long)
Context: ...---------------| | Homepage | Homepage | | Login | Login | | Login With Code | Login With Code | | Send Message | Send Message | | Send Image | Send Image | | Send File | Send File | | Send Video | Send Video | | Send Contact | Send Contact | | Send Location | Send Location | | Send Audio | Send Audio | | Send Poll | Send Poll | | Revoke Message | Revoke Message | | Delete Message | Delete Message | | Reaction Message | Reaction Message | | Edit Message | Edit Message | | User Info | User Info | | User Avatar | User Avatar | | My Privacy | My Privacy | | My Group | My Group | | Auto Reply | Auto Reply | | Basic Auth Prompt | Basic Auth Prompt | | Manage Participant | ![Manage Participant](https://i.ibb.co.co...

(EN_EXCESSIVE_EXCLAMATION)

Additional comments not posted (17)
docker/golang.Dockerfile (2)

4-4: Update to Go and Alpine versions.

The base image for the builder has been updated to golang:1.22.5-alpine3.20. This ensures that the application is built using the latest Go version and Alpine Linux version, which may include important security patches and performance improvements.


17-17: Update to Alpine version.

The final image has been updated to alpine:3.20. This ensures that the runtime environment benefits from the latest updates and security patches available in Alpine Linux.

src/validations/app_validation.go (2)

1-9: Imports and package declaration.

The necessary packages are imported for validation and error handling. The ozzo-validation library is used for validation, and a custom error package is used for error handling.


11-20: Validate phone number format.

The function ValidateLoginWithCode validates the phone number format using a regular expression. This ensures that the phone number is in a valid format before proceeding with the login process.

src/domains/app/app.go (1)

10-10: Addition of LoginWithCode method.

The LoginWithCode method has been added to the IAppService interface. This method allows users to log in using a code sent to their phone, enhancing the authentication options available in the application.

src/views/components/AppLoginWithCode.js (2)

6-15: Verify the necessity of jQuery.

Consider using Vue's built-in methods or libraries instead of jQuery for better integration and maintainability.

Are you sure jQuery is necessary here? Vue provides ways to handle DOM manipulations that might be more appropriate.


17-22: LGTM!

The data property is correctly defined.

src/services/app.go (2)

Line range hint 1-21:
LGTM!

The imports are appropriate for the new method.


Line range hint 23-93:
LGTM!

The existing code is unaffected by the new changes.

Also applies to: 112-197

src/views/index.html (3)

131-131: LGTM!

The import statement for AppLoginWithCode is correct and necessary.


175-178: LGTM!

The component registration for AppLoginWithCode is correct and necessary.


47-47: LGTM!

The new component usage for AppLoginWithCode is correctly integrated.

readme.md (2)

139-164: LGTM! Verify the accuracy of images and descriptions.

The new "User Interface" section with updated images and descriptions enhances the documentation.

Ensure that the images and descriptions accurately reflect the application's features.

Tools
LanguageTool

[style] ~143-~143: Using many exclamation marks might seem excessive (in this case: 26 exclamation marks for a text that’s 7858 characters long)
Context: ...---------------| | Homepage | Homepage | | Login | Login | | Login With Code | Login With Code | | Send Message | Send Message | | Send Image | Send Image | | Send File | Send File | | Send Video | Send Video | | Send Contact | Send Contact | | Send Location | Send Location | | Send Audio | Send Audio | | Send Poll | Send Poll | | Revoke Message | Revoke Message | | Delete Message | Delete Message | | Reaction Message | Reaction Message | | Edit Message | Edit Message | | User Info | User Info | | User Avatar | User Avatar | | My Privacy | My Privacy | | My Group | My Group | | Auto Reply | Auto Reply | | Basic Auth Prompt | Basic Auth Prompt | | Manage Participant | ![Manage Participant](https://i.ibb.co.co...

(EN_EXCESSIVE_EXCLAMATION)


103-104: LGTM! Verify the new login method.

The update to specify "Login with Scan QR" and the addition of "Login With Pair Code" improves clarity.

Ensure that the new login method is correctly implemented and documented in the codebase.

docs/openapi.yaml (3)

4-4: LGTM! Version update approved.

The API version increment from 4.1.0 to 4.2.0 is appropriate for the new features introduced.


1270-1284: LGTM! Verify the new response schema usage.

The new response schema LoginWithCodeResponse is well-defined.

Ensure that the new response schema is correctly used in the codebase.

Verification successful

The LoginWithCodeResponse schema is referenced correctly in the docs/openapi.yaml file. However, we need to verify the context in which it is used to ensure it is applied correctly in the API response definitions.


To ensure the correct usage of the LoginWithCodeResponse schema, we need to identify the specific endpoints and response codes that utilize it.


To ensure the correct usage of the LoginWithCodeResponse schema, we need to identify the specific endpoints and response codes that utilize it. Let's perform a search for all response schemas in the docs/openapi.yaml file to get a comprehensive view.


Usage of the new response schema is correct.

The LoginWithCodeResponse schema is correctly used in the /app/login-with-code endpoint for a 200 response.

  • /app/login-with-code endpoint uses LoginWithCodeResponse for a 200 response.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new response schema.

# Test: Search for the usage of the new response schema. Expect: Correct usage of the new response schema.
rg --type yaml -A 5 $'LoginWithCodeResponse'

Length of output: 588


Script:

#!/bin/bash
# Description: Verify the context of the usage of the new response schema.

# Test: Search for the usage of the new response schema and include more context lines to understand its application.
rg --type yaml -A 10 $'LoginWithCodeResponse'

Length of output: 1006


Script:

#!/bin/bash
# Description: Identify specific endpoints and response codes using the new response schema.

# Test: Search for the usage of the new response schema and include sufficient context lines to identify the endpoints and response codes.
rg --type yaml -A 20 $'LoginWithCodeResponse'

Length of output: 1852


Script:

#!/bin/bash
# Description: Identify all response schemas in the openapi.yaml file to understand the usage of LoginWithCodeResponse.

# Test: Search for all response schemas in the openapi.yaml file.
rg --type yaml -A 10 'schema:'

Length of output: 41482


39-64: LGTM! Verify the new endpoint implementation.

The new endpoint /app/login-with-code is well-documented with detailed specifications.

Ensure that the new endpoint is correctly implemented in the codebase.

src/views/components/AppLoginWithCode.js Outdated Show resolved Hide resolved
src/views/components/AppLoginWithCode.js Outdated Show resolved Hide resolved
src/views/components/AppLoginWithCode.js Show resolved Hide resolved
src/views/components/AppLoginWithCode.js Outdated Show resolved Hide resolved
src/validations/app_validation_test.go Outdated Show resolved Hide resolved
src/services/app.go Outdated Show resolved Hide resolved
src/internal/rest/app.go Show resolved Hide resolved
src/views/components/AppLogin.js Outdated Show resolved Hide resolved
src/views/components/AppLogin.js Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 221d638 and 7088edd.

Files selected for processing (5)
  • src/pkg/error/app_error.go (1 hunks)
  • src/services/app.go (2 hunks)
  • src/validations/app_validation_test.go (1 hunks)
  • src/views/components/AppLogin.js (3 hunks)
  • src/views/components/AppLoginWithCode.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/pkg/error/app_error.go
Files skipped from review as they are similar to previous changes (4)
  • src/services/app.go
  • src/validations/app_validation_test.go
  • src/views/components/AppLogin.js
  • src/views/components/AppLoginWithCode.js

@aldinokemal aldinokemal merged commit 7eb1de0 into main Jul 29, 2024
9 checks passed
@aldinokemal aldinokemal deleted the feat/login-with-pair-code branch July 29, 2024 14:52
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.

1 participant