Skip to content

fix: resolve login state issue preventing navigation (#504)#515

Open
sahu-virendra-1908 wants to merge 3 commits intoCircuitVerse:masterfrom
sahu-virendra-1908:fix/login-issue-504
Open

fix: resolve login state issue preventing navigation (#504)#515
sahu-virendra-1908 wants to merge 3 commits intoCircuitVerse:masterfrom
sahu-virendra-1908:fix/login-issue-504

Conversation

@sahu-virendra-1908
Copy link
Copy Markdown

@sahu-virendra-1908 sahu-virendra-1908 commented Mar 1, 2026

Fixes #504

Problem

After successful login, the token was correctly received and stored in SharedPreferences.
However, the login state was incorrectly set to Error, preventing navigation to CVLandingView.

Root Cause

The login ViewModel was overriding the state to Error despite successful authentication.

Changes Made

  • Corrected login state handling logic
  • Ensured Success state is triggered only after valid token response
  • Removed incorrect error state override
  • Verified proper navigation to CVLandingView

Result

  • Token is stored successfully
  • is_logged_in is set to true
  • App navigates correctly to CVLandingView
  • Error snackbar no longer appears after successful login

No UI changes. This is a state management fix.

Summary by CodeRabbit

  • Bug Fixes

    • Improved login resilience—users can now successfully log in even if profile data retrieval experiences temporary issues
  • Chores

    • Updated Android SDK versions and build tools for enhanced platform compatibility
    • Upgraded Gradle and plugin versions to latest releases
    • Refined project configuration and dependency management

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 1, 2026

Deploy Preview for cv-mobile-app-web ready!

Name Link
🔨 Latest commit 2ad94f0
🔍 Latest deploy log https://app.netlify.com/projects/cv-mobile-app-web/deploys/69a44e9bb8b51f00087b28f4
😎 Deploy Preview https://deploy-preview-515--cv-mobile-app-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 1, 2026

Walkthrough

This pull request updates Android build dependencies and configuration while refactoring the authentication flow. The Android SDK versions are bumped (compileSdk to 36, minSdkVersion to 24, targetSdkVersion to 36), Gradle wrapper is updated from 8.10.2 to 8.11.1, and Gradle plugins are upgraded (com.android.application to 8.9.1 and Kotlin to 2.1.0). Configuration adjustments include fixing a .gitignore pattern, adding FVM cache entries, removing a synthetic-package directive from l10n.yaml, and pinning a shared_preferences dependency. The login viewmodel is refactored to store the authentication token and mark the user as logged in immediately, with current user data fetched asynchronously without blocking login success.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Several changes go beyond the core login state fix. Android SDK bumps, Gradle/plugin version updates, .gitignore modifications, and shared_preferences downgrade are ancillary to fixing the login navigation issue. Separate Android toolchain updates and dependency changes into a dedicated PR; keep this PR focused solely on the login state fix in login_viewmodel.dart and l10n.yaml configuration.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main fix: resolving a login state issue preventing navigation, which is the core purpose of this PR.
Linked Issues check ✅ Passed The PR addresses issue #504 by fixing login state handling in the ViewModel. The login flow now stores token, marks user logged in, and sets Success state without erroneously overriding it to Error.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (1)
.gitignore (1)

47-49: Consider committing .fvmrc for team consistency.

The .fvm/ directory (cache) should be ignored, but .fvmrc contains the Flutter version configuration for the project. Committing .fvmrc ensures all team members use the same Flutter version.

Proposed change to commit .fvmrc
 # FVM Version Cache
 .fvm/
-.fvmrc

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f621531 and 2ad94f0.

⛔ Files ignored due to path filters (1)
  • pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • .gitignore
  • android/app/build.gradle
  • android/gradle/wrapper/gradle-wrapper.properties
  • android/settings.gradle
  • l10n.yaml
  • lib/viewmodels/authentication/login_viewmodel.dart
  • pubspec.yaml
💤 Files with no reviewable changes (1)
  • l10n.yaml

Comment on lines +25 to +35
// Step 3: Fetch current user (non-blocking)
// If this fails, user is still logged in with token
try {
_storage.currentUser = await _userApi.fetchCurrentUser();
print("_storage.currentUser: ${_storage.currentUser}");
} on Failure catch (e) {
// Log the error but don't fail the login
print('Warning: Failed to fetch current user: ${e.message}');
// User will be fetched later when accessing profile or landing screen
_storage.currentUser = null;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

rg -n "currentUser" --type=dart -C 2 | head -100

Repository: CircuitVerse/mobile-app

Length of output: 8341


🏁 Script executed:

rg -n "currentUser\s*[!=]=\s*null|currentUser\?" --type=dart

Repository: CircuitVerse/mobile-app

Length of output: 543


🏁 Script executed:

rg -n "CVLandingView|LandingView" --type=dart -C 2 | head -50

Repository: CircuitVerse/mobile-app

Length of output: 3560


🏁 Script executed:

cat -n lib/viewmodels/profile/user_favourites_viewmodel.dart | sed -n '50,80p'

Repository: CircuitVerse/mobile-app

Length of output: 1441


🏁 Script executed:

cat -n lib/viewmodels/profile/user_projects_viewmodel.dart | sed -n '45,75p'

Repository: CircuitVerse/mobile-app

Length of output: 1419


🏁 Script executed:

cat -n lib/viewmodels/cv_landing_viewmodel.dart | sed -n '55,75p'

Repository: CircuitVerse/mobile-app

Length of output: 664


🏁 Script executed:

fd -n "cv_landing.*view" --type=dart lib/ui/views | head -5

Repository: CircuitVerse/mobile-app

Length of output: 297


🏁 Script executed:

fd "cv_landing" --type=dart lib/ui/views

Repository: CircuitVerse/mobile-app

Length of output: 238


🏁 Script executed:

rg -n "fetchUserFavourites|fetchUserProjects" --type=dart -B5 -A5 | head -80

Repository: CircuitVerse/mobile-app

Length of output: 7540


🏁 Script executed:

cat -n lib/ui/views/cv_landing_view.dart | head -100

Repository: CircuitVerse/mobile-app

Length of output: 4220


🏁 Script executed:

cat -n lib/ui/views/profile/profile_view.dart | head -80

Repository: CircuitVerse/mobile-app

Length of output: 3455


Add null-safety checks for currentUser in profile-related viewmodels.

When fetchCurrentUser fails, currentUser is set to null but login succeeds. However, UserFavouritesViewModel (lines 64, 72) and UserProjectsViewModel (lines 56, 64) use non-null assertions (currentUser!.data.id) when no explicit userId is provided. This will crash when a logged-in user with null currentUser navigates to their profile.

Either guard these methods with null checks before accessing currentUser, use safe navigation (currentUser?.data.id), or implement the retry mechanism mentioned in your comment (line 33) to fetch currentUser when accessing the profile screen.

Comment on lines +29 to +32
print("_storage.currentUser: ${_storage.currentUser}");
} on Failure catch (e) {
// Log the error but don't fail the login
print('Warning: Failed to fetch current user: ${e.message}');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Remove debug print statements before merging.

The print() calls are debug artifacts that should be removed or replaced with proper logging infrastructure. These can leak user information in production logs.

Remove debug print statements
       try {
         _storage.currentUser = await _userApi.fetchCurrentUser();
-        print("_storage.currentUser: ${_storage.currentUser}");
       } on Failure catch (e) {
         // Log the error but don't fail the login
-        print('Warning: Failed to fetch current user: ${e.message}');
+        // Consider using a proper logging framework here
         // User will be fetched later when accessing profile or landing screen
         _storage.currentUser = null;
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
print("_storage.currentUser: ${_storage.currentUser}");
} on Failure catch (e) {
// Log the error but don't fail the login
print('Warning: Failed to fetch current user: ${e.message}');
try {
_storage.currentUser = await _userApi.fetchCurrentUser();
} on Failure catch (e) {
// Log the error but don't fail the login
// Consider using a proper logging framework here
// User will be fetched later when accessing profile or landing screen
_storage.currentUser = null;
}

Comment thread pubspec.yaml
scroll_to_index: ^3.0.1
share_plus: ^11.1.0
shared_preferences: ^2.5.4
shared_preferences: 2.5.3
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

git ls-files | grep -E "pubspec\.yaml|\.git" | head -20

Repository: CircuitVerse/mobile-app

Length of output: 538


🏁 Script executed:

cat -n pubspec.yaml | head -60

Repository: CircuitVerse/mobile-app

Length of output: 2346


🏁 Script executed:

# Check if there's git history to see what changed
git log --oneline --all -20 2>/dev/null || echo "No git history available"

Repository: CircuitVerse/mobile-app

Length of output: 1592


🏁 Script executed:

# Query pub.dev API for shared_preferences information
echo "=== Latest shared_preferences version ===" && \
curl -s "https://pub.dev/api/packages/shared_preferences" | jq '.latest.version' 2>/dev/null || echo "Could not fetch latest"

echo -e "\n=== Version 2.5.3 environment requirements ===" && \
curl -s "https://pub.dev/api/packages/shared_preferences/versions/2.5.3" 2>/dev/null | jq '.pubspec.environment' || echo "Could not fetch 2.5.3 info"

echo -e "\n=== Version 2.5.4 environment requirements ===" && \
curl -s "https://pub.dev/api/packages/shared_preferences/versions/2.5.4" 2>/dev/null | jq '.pubspec.environment' || echo "Could not fetch 2.5.4 info"

Repository: CircuitVerse/mobile-app

Length of output: 306


🏁 Script executed:

# Check if there's a comment in pubspec.yaml explaining the shared_preferences pin
sed -n '50,60p' pubspec.yaml

Repository: CircuitVerse/mobile-app

Length of output: 331


Add a comment explaining the Dart SDK constraint.

The exact pin to 2.5.3 is necessary, not discretionary. The project's minimum Dart SDK is 3.7.2, but shared_preferences 2.5.4 requires Dart 3.9.0. Version 2.5.3 is the latest compatible release for the current SDK constraint.

Add an inline comment above the dependency to document this constraint so future maintainers understand why the version is pinned:

  # Pinned to 2.5.3: shared_preferences 2.5.4 requires Dart 3.9.0, but this project supports 3.7.2+
  shared_preferences: 2.5.3

To upgrade to 2.5.4, the project's minimum Dart SDK must be bumped to 3.9.0 or higher.

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.

Login succeeds but app does not navigate to landing screen

1 participant