Skip to content

fix: replace push with pushReplacement in login navigation to prevent…#1057

Open
vibhutomer wants to merge 1 commit into
mosip:masterfrom
vibhutomer:fix/login-navigation-leak
Open

fix: replace push with pushReplacement in login navigation to prevent…#1057
vibhutomer wants to merge 1 commit into
mosip:masterfrom
vibhutomer:fix/login-navigation-leak

Conversation

@vibhutomer
Copy link
Copy Markdown

@vibhutomer vibhutomer commented May 13, 2026

Description

This PR resolves a critical navigation lifecycle bug where the LoginPage was left in the active routing stack after a successful authentication.

Previously, _navigateToHomePage() utilized Navigator.of(context).push(). This allowed authenticated users to press the hardware back button from the Dashboard and inadvertently return to the Login screen, resulting in a broken User Experience and improper session flow.

Changes Made

  • Updated the navigation method in login_page.dart from .push() to .pushReplacement().
  • This ensures that the authentication UI is destroyed and removed from the stack once the user successfully reaches the DashBoardTabletView.

Related Issue

Closes #1056

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • UX improvement (Fixes broken hardware back-button behavior)

Checklist

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • My changes generate no new warnings or exceptions.

Summary by CodeRabbit

  • Bug Fixes
    • Improved navigation behavior after login to prevent users from returning to the login page via the back button.

Review Change Stack

… stack leaks

Signed-off-by: vibhutomer <vibhutomer25@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Walkthrough

The login page navigation logic is updated to use pushReplacement instead of push when transitioning to the dashboard after successful authentication, removing the login screen from the navigation stack and preventing users from returning to the login page when pressing the back button.

Changes

Login Navigation Stack Fix

Layer / File(s) Summary
Dashboard navigation replacement
lib/ui/login_page.dart
_navigateToHomePage() changes from Navigator.of(context).push() to Navigator.of(context).pushReplacement() to replace the login route instead of stacking it, preventing back-button navigation to the login screen.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A hop through the nav stack so deep,
No more logins in layers to keep,
Replace, don't just push—
The session won't gush,
Now Back leads to dreams, not a beep! 🔙✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: replacing push with pushReplacement in login navigation to prevent back-button navigation issues.
Linked Issues check ✅ Passed The PR successfully replaces Navigator.push() with Navigator.pushReplacement() in login_page.dart, directly addressing issue #1056's requirement to remove the LoginPage from the navigation stack after authentication.
Out of Scope Changes check ✅ Passed The change is minimal and focused, modifying only the navigation method in _navigateToHomePage() with no unrelated alterations to other files or functionality.
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

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.

🧹 Nitpick comments (1)
lib/ui/login_page.dart (1)

372-389: 💤 Low value

Consider using pushAndRemoveUntil as a more concise alternative.

The current pattern of popUntil followed by pushReplacement correctly solves the navigation issue. However, you could simplify this to a single navigation call using pushAndRemoveUntil:

Alternative implementation
-      Navigator.popUntil(context, ModalRoute.withName('/login-page'));
-
       if (authProvider.isOnboarded || authProvider.isDefault) {
         globalProvider.setCurrentIndex(1);
       } else {
         globalProvider.setCurrentIndex(0);
       }

       if (!context.mounted) return;
-      Navigator.of(context).pushReplacement(
+      Navigator.of(context).pushAndRemoveUntil(
         MaterialPageRoute(
           builder: (context) => Responsive(
             mobile: DashBoardTabletView(),
             desktop: DashBoardTabletView(),
             tablet: DashBoardTabletView(),
           ),
         ),
+        (route) => false, // Remove all routes from the stack
       );

Note: If you need to preserve any routes below the login page (e.g., a splash screen), the current pattern is more appropriate. The suggested pushAndRemoveUntil with (route) => false clears the entire navigation stack.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/ui/login_page.dart` around lines 372 - 389, Replace the two-step
navigation (Navigator.popUntil(... ModalRoute.withName('/login-page')) followed
by Navigator.of(context).pushReplacement(... Responsive(...
DashBoardTabletView()))) with a single Navigator.of(context).pushAndRemoveUntil
call that pushes the Responsive/DashBoardTabletView route and removes previous
routes (or use a predicate that preserves the splash route if needed); update
the code paths that currently reference ModalRoute.withName('/login-page') and
pushReplacement so only the new pushAndRemoveUntil is used, keeping the existing
globalProvider.setCurrentIndex(...) logic intact before the navigation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lib/ui/login_page.dart`:
- Around line 372-389: Replace the two-step navigation (Navigator.popUntil(...
ModalRoute.withName('/login-page')) followed by
Navigator.of(context).pushReplacement(... Responsive(...
DashBoardTabletView()))) with a single Navigator.of(context).pushAndRemoveUntil
call that pushes the Responsive/DashBoardTabletView route and removes previous
routes (or use a predicate that preserves the splash route if needed); update
the code paths that currently reference ModalRoute.withName('/login-page') and
pushReplacement so only the new pushAndRemoveUntil is used, keeping the existing
globalProvider.setCurrentIndex(...) logic intact before the navigation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0700fcf4-3177-47fb-b1c4-00dfe4e39977

📥 Commits

Reviewing files that changed from the base of the PR and between aef4fb6 and 3e84727.

📒 Files selected for processing (1)
  • lib/ui/login_page.dart

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 screen remains in navigation stack causing Back-Button Session Leak

1 participant