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

[platform] : (Fix) Login Issue for most Users #2551

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from

Conversation

OchiengPaul442
Copy link
Contributor

@OchiengPaul442 OchiengPaul442 commented Mar 9, 2025

Summary of Changes (What does this PR do?)

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done
  • This change ready to hit production in its current state

Screenshots (optional)

Summary by CodeRabbit

  • Refactor

    • Enhanced the login flow by improving how the appropriate user group is selected based on user preferences.
  • Bug Fixes

    • Introduced a clearer error handling mechanism that prompts users to contact support when a valid user group cannot be determined.

Copy link

coderabbitai bot commented Mar 9, 2025

📝 Walkthrough

Walkthrough

The changes update the UserLogin component in the login page. The logic for determining the active user group has been refactored to first verify that user preferences exist and that the first preference contains a valid group ID. If those conditions are not met, the fallback is to find a group with the title "airqo". If no valid group is found, an error is thrown, prompting the user to contact support. Additionally, the local storage assignment for activeGroup now occurs after these validations.

Changes

File Path Change Summary
src/platform/src/pages/account/login/index.jsx Refactored active group determination in the UserLogin component: checks for valid group in preferences, uses fallback lookup for "airqo", and throws error if none found.

Sequence Diagram(s)

sequenceDiagram
    participant UL as UserLogin Component
    participant PS as Preferences Service
    participant LS as LocalStorage

    UL->>PS: Fetch user preferences
    PS-->>UL: Return preferences
    alt Valid preference with group_id exists
        UL->>UL: Assign activeGroup from preference
    else
        UL->>UL: Search for fallback group "airqo"
    end
    alt activeGroup found
        UL->>LS: Save activeGroup to local storage
    else
        UL->>UL: Throw error (contact support)
    end
Loading

Possibly related PRs

Suggested reviewers

  • Baalmart

Poem

Amidst the code where logic weaves,
A group is found, their path conceived.
From checks and fallbacks, errors recede,
A stable flow, our code's newfound creed.
Cheers to changes that help us succeed!
🚀✨

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, 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 or @coderabbitai title 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

@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 (2)
src/platform/src/pages/account/login/index.jsx (2)

76-86: Improved preference validation logic

The change correctly adds validation to check if preferences exist and have a valid group_id before trying to access them. This is a robust approach that prevents potential runtime errors.

However, there's a minor issue: the code doesn't handle the case where user.groups might be undefined, which could happen in edge cases.

Consider adding an additional check to ensure user.groups is defined before calling find:

// Try to get the group from the first preference if exists and valid
if (preferences.length > 0 && preferences[0].group_id) {
-  activeGroup = user.groups.find(
+  activeGroup = user.groups?.find(
    (group) => group._id === preferences[0].group_id,
  );
}

87-92: Good fallback mechanism implementation

The fallback to find a group with the title 'airqo' is sensible and ensures users can still log in even if their preferences don't contain a valid group.

Consider making the group title comparison case-insensitive to make it more robust:

if (!activeGroup) {
  activeGroup = user.groups.find(
-    (group) => group.grp_title.toLowerCase() === 'airqo',
+    (group) => group.grp_title?.toLowerCase() === 'airqo',
  );
}

This includes a null check on grp_title and ensures the comparison works regardless of the case stored in the database.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c88999 and 8131b9e.

📒 Files selected for processing (1)
  • src/platform/src/pages/account/login/index.jsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-push-deploy-analytics-platform-preview
🔇 Additional comments (2)
src/platform/src/pages/account/login/index.jsx (2)

93-98: Appropriate error handling added

Good addition of explicit error handling when no valid group is found. This provides a clear message for users and guides them to contact support.


100-100: Correctly relocated localStorage assignment

Moving the localStorage assignment for activeGroup to occur after all validations is correct. This ensures we only store a valid group in localStorage.

Copy link
Contributor

github-actions bot commented Mar 9, 2025

New next-platform changes available for preview here

1 similar comment
Copy link
Contributor

github-actions bot commented Mar 9, 2025

New next-platform changes available for preview here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant