Skip to content

#142 if user is verified after registration put the changes to the database#162

Open
IhorMasechko wants to merge 23 commits into
mainfrom
142-if-user-is-verified-after-registration-put-the-changes-to-the-database
Open

#142 if user is verified after registration put the changes to the database#162
IhorMasechko wants to merge 23 commits into
mainfrom
142-if-user-is-verified-after-registration-put-the-changes-to-the-database

Conversation

@IhorMasechko
Copy link
Copy Markdown
Contributor

@IhorMasechko IhorMasechko commented Apr 7, 2025

Added Gmail messenger and set the flag to true after successful verification

Summary by CodeRabbit

  • New Features

    • Upgraded the email delivery process by integrating nodemailer, enhancing the verification experience with updated messaging.
    • Added a verification step for unverified users during login, improving the user experience.
    • Introduced toast notifications for user feedback instead of alert dialogs.
    • Added a Toaster component for displaying notifications in the app layout.
    • Enhanced user verification flow with GraphQL integration and improved access control for verification status updates.
  • Tests

    • Refined testing for the EmailVerification component, ensuring comprehensive coverage of various scenarios including success and error handling.
    • Enhanced testing for login functionality to verify behavior during authentication failures, including network errors.
    • Added a new test case in the RegisterForm tests to simulate network errors during login.
    • Consolidated and expanded mocks for login-related tests to improve coverage and maintainability.
  • Chores

    • Updated project dependencies to support the improved email system and added support for toast notifications.
    • Adjusted session cookie security settings to always use sameSite='none' and secure=true attributes.

@IhorMasechko IhorMasechko self-assigned this Apr 7, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 7, 2025

📝 Walkthrough
## Walkthrough
This PR replaces the Resend email service with nodemailer across the application. The API endpoint and its tests have been updated to use a nodemailer transport and mock, respectively, for sending emails. The package dependencies have been adjusted accordingly. In the frontend, the EmailVerification and RegisterForm components now pass the user's email along with the verification code, integrating GraphQL queries and mutations to handle user verification. Additionally, a GraphQL constant has been renamed, and the Keystone user model’s access control for the verification field has been broadened. The login flow is enhanced to include email verification for unverified users, with toast notifications added for user feedback.

## Changes

| File(s) | Change Summary |
|---------|----------------|
| `veterans/app/api/sendEmail/route.ts`, `veterans/app/api/sendEmail/route.test.ts`, `veterans/package.json` | Replaced Resend with nodemailer: updated email transport instantiation and email content in the API, integrated a nodemailer mock in tests, and updated dependencies by removing `resend` and adding `nodemailer` with its types. Added `react-hot-toast` dependency. |
| `veterans/components/common/authForm/EmailVerification/EmailVerification.tsx`, `veterans/components/common/authForm/RegisterForm.tsx` | Enhanced verification: added an email reference/prop to pass user email, integrated Apollo Client GraphQL queries and mutations for user verification, updated error handling, and added redirection logic. |
| `veterans/constants/graphql.ts`, `veterans/keystone/models/User.ts` | Updated backend logic: renamed mutation constant from `UPDATE_USER_VERIFICATION` to `VERIFICATION_MUTATION`, added `isVerified` field to `LOGIN_MUTATION`, and changed `isVerified` field access control to allow both admins and users to update it. |
| `veterans/app/layout.tsx` | Added `Toaster` component from `react-hot-toast` for toast notifications in the layout. |
| `veterans/components/common/authForm/LoginForm.tsx` | Introduced new login flow with verification step for unverified users, including state management for verification code and step tracking, integration of email sending helper, and conditional rendering of verification component. |
| `veterans/helpers/handleSendEmail.ts` | Replaced alert notification with toast notification for email verification success feedback. |
| `veterans/components/common/authForm/LoginForm.test.tsx`, `veterans/components/common/authForm/EmailVerification/EmailVerification.test.tsx` | Updated tests: restructured mocks in `LoginForm` tests, added `isVerified` field in mocks, added new test suite for `EmailVerification` covering various scenarios including error handling and user interactions. |
| `veterans/components/common/authForm/RegisterForm.test.tsx` | Extended tests to include login error handling and network error scenarios; updated placeholder text for verification code input. |
| `veterans/auth.ts` | Updated session cookie settings to use `sameSite` and `secure` attributes conditionally based on environment (production vs non-production). |

## Possibly related PRs
- **boarlabsxyz/razom#147**: Involves similar changes in email sending functionality by transitioning from Resend to nodemailer and updating tests to simulate email delivery.
- **boarlabsxyz/razom#155**: Related to the introduction and handling of the `isVerified` field in user verification flows, including GraphQL mutations and access control.
- **boarlabsxyz/razom#90**: Introduces the `isAdminOrSameUser` access control function used here to broaden update permissions on the `isVerified` field.

## Suggested reviewers
- yuramax
- VitalyyP
- Anton-88

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b9516b and 253c610.

📒 Files selected for processing (1)
  • veterans/auth.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • veterans/auth.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: deployment
  • GitHub Check: unit-tests
  • GitHub Check: e2e-tests

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link
Copy Markdown

@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: 2

🧹 Nitpick comments (1)
veterans/app/api/sendEmail/route.ts (1)

23-28: Improve the email sender display name.

Currently, the from field uses just the email address from environment variables. For better user experience, consider adding a friendly display name.

- from: process.env.GMAIL_USER,
+ from: `Razom Veterans <${process.env.GMAIL_USER}>`,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a141fa6 and a384c93.

⛔ Files ignored due to path filters (1)
  • veterans/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • veterans/app/api/sendEmail/route.test.ts (2 hunks)
  • veterans/app/api/sendEmail/route.ts (2 hunks)
  • veterans/helpers/handleSendEmail.ts (1 hunks)
  • veterans/package.json (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
veterans/app/api/sendEmail/route.test.ts (1)
veterans/app/api/sendEmail/route.ts (1)
  • POST (4-45)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: e2e-tests
  • GitHub Check: unit-tests
🔇 Additional comments (8)
veterans/package.json (2)

40-40: Dependencies updated appropriately.

The addition of the nodemailer package aligns with the PR objective of replacing Resend with a Gmail-based email solution. The version chosen (^6.10.0) is appropriate.


64-64: Type definitions properly added.

Adding @types/nodemailer to devDependencies is the correct approach for TypeScript support. The version chosen (^6.4.17) matches the nodemailer package requirement.

veterans/app/api/sendEmail/route.test.ts (4)

1-5: Nodemailer mock implementation looks good.

The mock appropriately simulates the nodemailer transport and sendMail method, returning a test message ID that can be verified in the tests.


7-16: NextResponse mock correctly updated.

The mock now returns a proper Response object with the correct status and content type headers, which better simulates the actual Next.js response behavior.


49-50: Test assertion properly checks message ID.

The test correctly verifies that the response includes the message ID from the successful email send operation.


53-71: Error handling test looks good.

The test properly overrides the sendMail method to simulate an error condition and verifies the correct error response is returned.

veterans/app/api/sendEmail/route.ts (2)

2-2: Nodemailer import looks good.

The import correctly brings in the nodemailer package that was added to the dependencies.


30-30: Email sending implementation is correct.

The implementation correctly awaits the result of transporter.sendMail() and passes it in the response, which is the expected pattern when using nodemailer.

Comment thread veterans/helpers/handleSendEmail.ts Outdated
Comment thread veterans/app/api/sendEmail/route.ts
coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 8, 2025
Copy link
Copy Markdown

@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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f98d561 and 805fe25.

📒 Files selected for processing (5)
  • veterans/app/api/sendEmail/route.ts (2 hunks)
  • veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (1 hunks)
  • veterans/components/common/authForm/RegisterForm.tsx (3 hunks)
  • veterans/constants/graphql.ts (1 hunks)
  • veterans/keystone/models/User.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • veterans/app/api/sendEmail/route.ts
🧰 Additional context used
🧬 Code Definitions (2)
veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (1)
veterans/constants/graphql.ts (2)
  • VERIFICATION_MUTATION (83-90)
  • CHECK_USER_QUERY (73-81)
veterans/components/common/authForm/RegisterForm.tsx (1)
veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (1)
  • EmailVerification (12-74)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: sonarqube
  • GitHub Check: e2e-tests
🔇 Additional comments (8)
veterans/constants/graphql.ts (1)

83-90: LGTM! The constant has been renamed to better reflect its purpose.

The renaming of the GraphQL mutation constant from UPDATE_USER_VERIFICATION to VERIFICATION_MUTATION improves code readability by better indicating its purpose in the verification flow. The implementation is consistent with other GraphQL queries and mutations in the file.

veterans/components/common/authForm/RegisterForm.tsx (3)

40-40: LGTM! The email reference is correctly initialized.

The emailRef provides a way to persist the email value across component renderings, which is necessary for the verification flow.


79-79: LGTM! Email is correctly stored for verification.

The user's email is properly stored in the ref after successful registration, making it available for the verification process.


205-208: LGTM! Email is correctly passed to the EmailVerification component.

The EmailVerification component now receives both the verification code and the email address, enabling it to perform the verification process correctly.

veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (4)

2-5: LGTM! Required imports for GraphQL functionality.

The imports for Apollo Client's useMutation and useQuery hooks, along with the GraphQL constants, are correctly added to support the new verification functionality.


9-9: LGTM! Interface properly updated to include email property.

The EmailVerificationProps interface has been correctly updated to include the email property, which is required for the verification process.


14-14: LGTM! Component correctly accepts the email prop.

The component function signature has been updated to destructure and use the email property from props.


17-21: LGTM! GraphQL hooks correctly implemented.

The implementation of the GraphQL hooks to query user data and update verification status is done correctly.

Comment thread veterans/keystone/models/User.ts Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 8, 2025
Copy link
Copy Markdown

@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

♻️ Duplicate comments (1)
veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (1)

30-30: ⚠️ Potential issue

Null-check on userData.user
In case userData or userData.user is null, accessing .id here can throw an error. Please add a null/undefined check before using userData.user.id.

Here’s a quick fix suggestion:

-    const userId = userData.user.id;
+    if (!userData?.user?.id) {
+      toast.error('Cannot find user data. Please refresh and try again.');
+      return;
+    }
+    const userId = userData.user.id;
🧹 Nitpick comments (4)
veterans/app/layout.tsx (1)

55-55: Positioning the Toaster
Placing the Toaster at top-center is a straightforward way to ensure any notifications appear prominently. If you plan to customize the style or behavior of these toasts, consider passing additional props to match your design specs. Otherwise, this is fine as-is.

veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (3)

18-18: Use of useMutation
Storing the mutation function in a constant is clean and follows best practices. Make sure to handle potential errors or loading states if you plan to display UI feedback during the request.


20-22: Fetching user data
Querying the user by email is a logical approach. Do keep in mind to handle query errors or empty results in a future iteration if the user does not exist in the database.


32-39: Performing the mutation
Good structure with updateUserVerification to set isVerified: true. You may wish to handle partial failures more explicitly (e.g., network or server errors) and display specific feedback.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 805fe25 and b4b3114.

⛔ Files ignored due to path filters (1)
  • veterans/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • veterans/app/layout.tsx (2 hunks)
  • veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (1 hunks)
  • veterans/components/common/authForm/LoginForm.tsx (5 hunks)
  • veterans/components/common/authForm/RegisterForm.tsx (5 hunks)
  • veterans/constants/graphql.ts (2 hunks)
  • veterans/helpers/handleSendEmail.ts (2 hunks)
  • veterans/keystone/models/User.ts (1 hunks)
  • veterans/package.json (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • veterans/package.json
  • veterans/constants/graphql.ts
  • veterans/keystone/models/User.ts
🧰 Additional context used
🧬 Code Graph Analysis (3)
veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (1)
veterans/constants/graphql.ts (2)
  • VERIFICATION_MUTATION (84-91)
  • CHECK_USER_QUERY (74-82)
veterans/components/common/authForm/RegisterForm.tsx (3)
veterans/constants/graphql.ts (2)
  • LOGIN_MUTATION (26-43)
  • CURRENT_USER_QUERY (3-14)
veterans/helpers/handleSendEmail.ts (1)
  • handleSendEmail (4-29)
veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (1)
  • EmailVerification (13-74)
veterans/components/common/authForm/LoginForm.tsx (2)
veterans/helpers/handleSendEmail.ts (1)
  • handleSendEmail (4-29)
veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (1)
  • EmailVerification (13-74)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e-tests
🔇 Additional comments (22)
veterans/app/layout.tsx (1)

2-2: Use of Toaster import
Thanks for introducing Toaster from react-hot-toast; this setup looks good for supporting toast notifications across the app.

veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (7)

2-3: Introduced toast notifications
Great usage of react-hot-toast for non-blocking error handling and user feedback. This improves the overall user experience compared to persistent alerts.


6-6: Centralized GraphQL imports
Good practice to import both VERIFICATION_MUTATION and CHECK_USER_QUERY from a single constants file for maintainability.


10-10: New email prop
Adding email to EmailVerificationProps makes the component more robust by using the passed-in email for queries and mutation variables.


15-15: Destructured email prop
Well-integrated into the component signature to facilitate the verification flow.


24-28: Code mismatch check
If the user’s confirmed code doesn’t match the actual verification code, displaying an error toast and returning early is clear and user-friendly. No concerns here.


40-44: Conditional post-mutation logic
Immediately navigating the user upon successful verification is a sensible flow. The fallback toast for failure is also appropriate.


45-51: Exception handling with toast
Your use of toast.error() here ensures users receive real-time feedback if an unexpected error occurs, which is a big UX improvement.

veterans/helpers/handleSendEmail.ts (2)

2-2: Swapping alerts for toast
Importing toast from react-hot-toast is consistent with your shift towards non-blocking feedback.


19-19: Success notification
Using toast.success() to confirm email dispatch is a clear improvement over alerts, ensuring the user stays in context.

veterans/components/common/authForm/RegisterForm.tsx (7)

9-9: Import update to support user authentication flow

The useApolloClient hook has been added which is necessary for writing the authenticated user data to the Apollo cache after registration.


12-16: Improved GraphQL imports organization

The imports are properly organized to include the CURRENT_USER_QUERY which is needed for updating the authentication state in the Apollo cache.


44-45: New refs added to manage user authentication

These refs are essential additions:

  • emailRef stores the user's email for verification purposes
  • client provides access to the Apollo client for cache updates

Both are necessary for the verification flow implementation.


65-82: Well-implemented login mutation with proper error handling

The login mutation implementation is robust with:

  • Proper handling of authentication success by updating the Apollo cache
  • Clear error handling to provide feedback to the user
  • Type checking with the 'item' property to ensure type safety

This implementation ensures a smooth user experience during the registration-to-login flow.


103-103: User email storage for verification

Storing the email in emailRef.current after successful registration is necessary for the verification process.


107-112: Auto-login after registration

Automatically logging in the user after successful registration is a good UX improvement, eliminating the need for the user to manually log in after registration.


235-238: Updated EmailVerification component usage

The email prop has been correctly added to the EmailVerification component, which is required for the verification process as described in the PR objectives.

veterans/components/common/authForm/LoginForm.tsx (5)

20-21: Added verification-related imports

These imports are necessary for implementing the email verification flow when unverified users attempt to log in.


35-35: Added getValues to access form data

Adding getValues to the destructured form hook values is necessary to retrieve the email value later in the code.


44-46: Added state for verification flow

These additions are well-structured:

  • verificationCode state stores the code sent to the user
  • stepRef tracks whether the user is in login or verification mode
  • emailRef retains the email for verification purposes

All of these are necessary for implementing the verification workflow.


131-153: Enhanced login flow with verification check

This implementation properly:

  1. Checks if the user is verified after successful login
  2. Guides unverified users through the verification process
  3. Redirects verified users to the home page

The code correctly retrieves and stores the user's email, sends a verification code, and manages the UI flow based on verification status.


165-251: Implemented conditional rendering for login/verification steps

This implementation provides a smooth user experience by:

  1. Showing the login form during the initial login step
  2. Switching to the verification component when needed
  3. Properly passing both verification code and email to the verification component

The structure is clean and maintains all the original login form functionality.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 9, 2025
Copy link
Copy Markdown

@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: 1

🔭 Outside diff range comments (1)
veterans/components/common/authForm/LoginForm.test.tsx (1)

113-236: 🛠️ Refactor suggestion

Consider adding tests for unverified user flow.

The test suite thoroughly covers successful login with verified users but lacks tests for the new unverified user flow. Since the component now handles a verification step for unverified users, additional tests should be added to ensure this path works correctly.

// Add this test after line 211
+ it('should show verification form for unverified users', async () => {
+   const unverifiedUserMock = [{
+     request: {
+       query: LOGIN_MUTATION,
+       variables: {
+         email: 'unverified@example.com',
+         password: 'Password123',
+       },
+     },
+     result: {
+       data: {
+         authenticateUserWithPassword: {
+           item: {
+             id: '2',
+             email: 'unverified@example.com',
+             role: 'USER',
+             name: 'Unverified User',
+             isVerified: false,
+           },
+         },
+       },
+     },
+   }];
+   
+   customRender(<LoginForm />, unverifiedUserMock);
+   fireEvent.change(screen.getByPlaceholderText('Email'), {
+     target: { value: 'unverified@example.com' },
+   });
+   fireEvent.change(screen.getByPlaceholderText('Password'), {
+     target: { value: 'Password123' },
+   });
+   fireEvent.click(screen.getByRole('button', { name: /sign in/i }));
+   
+   await waitFor(() => {
+     expect(screen.getByTestId('email-verification')).toBeInTheDocument();
+   });
+ });
🧹 Nitpick comments (3)
veterans/components/common/authForm/LoginForm.tsx (3)

129-151: Implemented conditional verification flow.

The implementation correctly checks if a user is verified and either redirects to the homepage or initiates the email verification process.

However, there are a few improvements that could be made to enhance the user experience:

  1. Add loading state during email sending
  2. Provide more informative error messages
  3. Add ability to retry sending verification email
try {
  const { data } = await login({ variables: formData });
  const authResult = data?.authenticateUserWithPassword;

  if (authResult && 'item' in authResult) {
    const isVerified = authResult.item?.isVerified;
    const userEmail = getValues('email');
    emailRef.current = userEmail;

    if (!isVerified) {
      stepRef.current = 'verify';
+     setIsSubmitting(true);

      const { success, code } = await handleSendEmail(userEmail);
      if (success && code) {
        setVerificationCode(code);
      } else {
-       setError('Failed to send verification email');
+       setError('Failed to send verification email. Please check your internet connection and try again.');
+       stepRef.current = 'login';
      }
+     setIsSubmitting(false);
    } else {
      router.push('/');
    }
  }

163-249: Implemented conditional rendering based on verification step.

The component now correctly renders either the login form or the verification component based on the current step. This structure works well, but some improvements could be made for user experience.

Consider adding a back button in the verification component to allow users to return to the login screen if needed:

<EmailVerification
  verificationCode={verificationCode}
  email={emailRef.current}
+ onBack={() => {
+   stepRef.current = 'login';
+   setError(null);
+   setSubmitError(null);
+   // Force a re-render
+   setIsSubmitting(false);
+ }}
/>

31-159: Consider refactoring for separation of concerns.

The LoginForm component is handling multiple responsibilities (login, OAuth, verification flow). Consider extracting some of this logic into separate components or custom hooks to improve maintainability.

For example, you could create:

  1. A custom hook for the login logic
  2. A custom hook for the OAuth flow
  3. Move the verification step into its own component

This would make the code more modular and easier to test.

// Example hook extraction
function useLoginForm() {
  const [isSubmitting, setIsSubmitting] = useState(false);
  const [submitError, setSubmitError] = useState(null);
  const [error, setError] = useState(null);
  const [verificationCode, setVerificationCode] = useState('');
  const stepRef = useRef('login');
  const emailRef = useRef('');
  
  // Login mutation and form handling logic
  
  return {
    isSubmitting,
    submitError,
    error,
    verificationCode,
    stepRef,
    emailRef,
    handleLogin,
    // other methods and state
  };
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b4b3114 and 00078a2.

📒 Files selected for processing (2)
  • veterans/components/common/authForm/LoginForm.test.tsx (1 hunks)
  • veterans/components/common/authForm/LoginForm.tsx (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: unit-tests
  • GitHub Check: e2e-tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
veterans/components/common/authForm/LoginForm.test.tsx (1)

38-38: Update verified user mock for login test consistency.

The added isVerified: true property in the login mock response aligns with the new verification functionality implemented in the LoginForm component. This ensures that tests for successful login and redirection work correctly with the updated GraphQL schema.

veterans/components/common/authForm/LoginForm.tsx (2)

20-21: Import of new verification components.

The component now correctly imports the required helper and component for the email verification flow.


44-46: Added state management for verification flow.

These state variables and refs effectively manage the verification step and user email persistence.

Comment thread veterans/components/common/authForm/LoginForm.tsx
coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 9, 2025
Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
veterans/components/common/authForm/EmailVerification/EmailVerification.test.tsx (1)

1-133: Consider enhancing accessibility in your tests.

While the current tests are comprehensive, consider using more accessibility-focused queries like getByRole or getByLabelText instead of getByPlaceholderText when possible, as they better represent how users (including those using assistive technologies) interact with your application.

- screen.getByPlaceholderText('Email verification')
+ screen.getByRole('textbox', { name: /email verification/i })

This would require adding an appropriate aria-label or label element in the component, which would improve both testability and accessibility.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00078a2 and 69dc92b.

📒 Files selected for processing (3)
  • veterans/components/common/authForm/EmailVerification/EmailVerification.test.tsx (1 hunks)
  • veterans/components/common/authForm/LoginForm.test.tsx (2 hunks)
  • veterans/components/common/authForm/LoginForm.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • veterans/components/common/authForm/LoginForm.test.tsx
  • veterans/components/common/authForm/LoginForm.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
veterans/components/common/authForm/EmailVerification/EmailVerification.test.tsx (1)
veterans/components/common/authForm/EmailVerification/EmailVerification.tsx (1)
  • EmailVerification (13-74)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: unit-tests
  • GitHub Check: e2e-tests
🔇 Additional comments (7)
veterans/components/common/authForm/EmailVerification/EmailVerification.test.tsx (7)

1-14: Good test setup with proper imports and mock configurations.

The imports and mock configurations are well-structured, covering all the necessary dependencies for thorough testing of the EmailVerification component.


16-33: Well-organized test suite setup.

Great job setting up the test suite with proper mocks for router and Apollo Client hooks. The beforeEach cleanup ensures tests don't influence each other.


35-44: Component rendering test looks good.

The rendering test appropriately verifies that key UI elements are present in the document.


46-60: Thorough validation of error handling for invalid codes.

Good test case that ensures the component correctly identifies and reports invalid verification codes.


62-87: Comprehensive happy path testing.

The test correctly verifies the successful email verification flow, including:

  • Mutation being called with correct parameters
  • User being redirected after successful verification

89-110: Good coverage of backend verification failure.

This test properly handles the scenario where the backend returns a false verification status, ensuring the appropriate error message is displayed.


112-131: Effective testing of network error scenarios.

The test correctly verifies error handling when a network error occurs during the mutation.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 10, 2025
coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 10, 2025
@IhorMasechko IhorMasechko removed the request for review from Anton-88 April 15, 2025 15:44
coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 15, 2025
coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 15, 2025
coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 16, 2025
@sonarqubecloud
Copy link
Copy Markdown

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.

If user is verified after registration, put the changes to the database

2 participants