Skip to content

fix(WEB-1077): redirect to originally requested URL after login - #3772

Open
Ruba-Tawk-FOO wants to merge 1 commit into
openMF:devfrom
foodeveloper:WEB-1077-redirect-to-requested-url-after-login
Open

fix(WEB-1077): redirect to originally requested URL after login#3772
Ruba-Tawk-FOO wants to merge 1 commit into
openMF:devfrom
foodeveloper:WEB-1077-redirect-to-requested-url-after-login

Conversation

@Ruba-Tawk-FOO

@Ruba-Tawk-FOO Ruba-Tawk-FOO commented Jul 29, 2026

Copy link
Copy Markdown

Preserve the attempted URL as a returnUrl query param when the authentication guard redirects an unauthenticated user to the login page, and navigate back to it after a successful login (falling back to the dashboard for missing/unsafe values).

Description

Describe the changes made and why they were made instead of how they were made. List any dependencies that are required for this change.

Related issues and discussion

#{Issue Number}

Screenshots, if any

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • If you have multiple commits please combine them into one commit by squashing them.

  • Read and understood the contribution guidelines at web-app/.github/CONTRIBUTING.md.

Summary by CodeRabbit

  • Bug Fixes
    • Preserved the originally requested page when redirecting unauthenticated visitors to the login screen.
    • After successful login, redirected users back to their intended destination instead of always sending them to the home page.
    • Improved redirect safety by validating the stored return destination, preventing login-loop scenarios, and falling back to the home page when the return URL is invalid.

@Ruba-Tawk-FOO
Ruba-Tawk-FOO requested a review from a team July 29, 2026 11:22
@mifos-cla-check

Copy link
Copy Markdown

👋 Hi @Ruba-Tawk-FOO — thank you for your pull request.

This PR is currently blocked because we do not have a Contributor License Agreement (CLA) on file for your GitHub account.

To get unblocked:

  1. Complete the form at https://mifos.org/about-us/financial-legal/mifos-contributor-agreement
  2. Complete the CLA signing process
  3. Once verified you will be added to the approved contributors list and this PR check will be cleared

@mifos-cla-check mifos-cla-check Bot added the cla-required CLA signature required before this PR can be merged label Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "pre_merge_checks"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 65e461b4-4556-412f-ac22-9d6648473b6b

📥 Commits

Reviewing files that changed from the base of the PR and between cab784d and 9cd08a7.

📒 Files selected for processing (2)
  • src/app/core/authentication/authentication.guard.ts
  • src/app/login/login.component.ts

Walkthrough

Authentication redirects now preserve safe in-app destination URLs through login. After successful authentication, users are redirected to the preserved destination instead of always navigating to the root route.

Changes

Authentication return URL

Layer / File(s) Summary
Guard redirect preservation
src/app/core/authentication/authentication.guard.ts
AuthenticationGuard receives router state and redirects unauthenticated requests to /login with an optional returnUrl while retaining replaceUrl.
Login return navigation
src/app/login/login.component.ts
LoginComponent reads and validates returnUrl, then navigates to it after successful authentication, falling back to /.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: alberto-art3ch

Sequence Diagram(s)

sequenceDiagram
  participant Router
  participant AuthenticationGuard
  participant LoginComponent
  Router->>AuthenticationGuard: Request protected URL
  AuthenticationGuard->>Router: Redirect to /login with returnUrl
  Router->>LoginComponent: Load login page
  LoginComponent->>Router: Navigate to validated returnUrl after authentication
Loading
🚥 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 accurately summarizes the main change: preserving and restoring the originally requested URL after login.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/app/login/login.component.ts (1)

237-243: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add focused tests for the return-URL contract.

Cover guard preservation and login validation for /, /login, valid paths with query/fragment data, external URLs, non-string query values, protocol-relative paths, and failed destination navigation.

🤖 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 `@src/app/login/login.component.ts` around lines 237 - 243, Add focused tests
around LoginComponent.getReturnUrl and the login navigation flow. Verify guard
preservation and validation for "/", "/login", valid paths with query strings or
fragments, external and protocol-relative URLs, non-string returnUrl values, and
failed destination navigation, preserving the expected safe fallback and error
behavior.
🤖 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.

Inline comments:
In `@src/app/login/login.component.ts`:
- Line 140: Update the post-login navigation around router.navigateByUrl to
handle both a false result and rejected navigation by falling back to the
dashboard route. Preserve replaceUrl behavior and use the existing dashboard
navigation mechanism.

---

Nitpick comments:
In `@src/app/login/login.component.ts`:
- Around line 237-243: Add focused tests around LoginComponent.getReturnUrl and
the login navigation flow. Verify guard preservation and validation for "/",
"/login", valid paths with query strings or fragments, external and
protocol-relative URLs, non-string returnUrl values, and failed destination
navigation, preserving the expected safe fallback and error behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 154d12d0-780f-4e2f-b839-1d287526bcca

📥 Commits

Reviewing files that changed from the base of the PR and between 5936f66 and aad6c4e.

📒 Files selected for processing (2)
  • src/app/core/authentication/authentication.guard.ts
  • src/app/login/login.component.ts

Comment thread src/app/login/login.component.ts Outdated
@IOhacker

Copy link
Copy Markdown
Contributor

@Ruba-Tawk-FOO could you please sign the CLA and also resolve the comment opened by CodeRabbit

@Ruba-Tawk-FOO
Ruba-Tawk-FOO force-pushed the WEB-1077-redirect-to-requested-url-after-login branch from aad6c4e to f8c28ec Compare July 30, 2026 08:57
@mifos-cla-check mifos-cla-check Bot removed the cla-required CLA signature required before this PR can be merged label Jul 30, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/app/login/login.component.ts (2)

241-252: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression coverage for the return URL contract.

Cover nested paths/query parameters/fragments, root and login fallbacks, duplicate values, unsafe schemes, and both unsuccessful and rejected post-login navigation.

🤖 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 `@src/app/login/login.component.ts` around lines 241 - 252, Add regression
tests around LoginComponent.getReturnUrl and the post-login navigation flow
covering nested paths with query parameters or fragments, root and login
fallbacks, duplicate returnUrl values, unsafe schemes, and navigation that is
both unsuccessful and rejected. Verify each case resolves to the expected safe
fallback or navigation outcome.

247-248: 📐 Maintainability & Code Quality | 🔵 Trivial

Use queryParamMap to keep returnUrl strictly typed.

this.route.snapshot.queryParams is typed as a generic Params map (string => any), so returnUrl loses strict string typing. Use this.route.snapshot.queryParamMap.getAll('returnUrl') and keep the existing runtime validation/array-handling before selecting the single value.

[loweffort_and_high_reward]

🤖 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 `@src/app/login/login.component.ts` around lines 247 - 248, Update the
returnUrl retrieval in the login component to use
this.route.snapshot.queryParamMap.getAll('returnUrl') instead of the generic
queryParams map. Preserve the existing runtime validation and array-handling,
then select the single validated value before applying the current URL checks.

Source: Coding guidelines

🤖 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 `@src/app/login/login.component.ts`:
- Around line 241-252: Add regression tests around LoginComponent.getReturnUrl
and the post-login navigation flow covering nested paths with query parameters
or fragments, root and login fallbacks, duplicate returnUrl values, unsafe
schemes, and navigation that is both unsuccessful and rejected. Verify each case
resolves to the expected safe fallback or navigation outcome.
- Around line 247-248: Update the returnUrl retrieval in the login component to
use this.route.snapshot.queryParamMap.getAll('returnUrl') instead of the generic
queryParams map. Preserve the existing runtime validation and array-handling,
then select the single validated value before applying the current URL checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 896bb3ed-066d-4693-b5c0-14b2f2404012

📥 Commits

Reviewing files that changed from the base of the PR and between aad6c4e and f8c28ec.

📒 Files selected for processing (2)
  • src/app/core/authentication/authentication.guard.ts
  • src/app/login/login.component.ts

@DavidH-1

Copy link
Copy Markdown
Contributor

Needs to be updated to match base branch too

@Ruba-Tawk-FOO
Ruba-Tawk-FOO force-pushed the WEB-1077-redirect-to-requested-url-after-login branch from f8c28ec to cab784d Compare July 30, 2026 09:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@src/app/login/login.component.ts`:
- Around line 246-251: Update getReturnUrl to reject query parameters beginning
with “//” in addition to the existing validation, before returning the supplied
URL. Preserve the current “/login” rejection and fallback to “/” for all invalid
return URLs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: cd5ba884-3730-499d-8537-a94a92369f69

📥 Commits

Reviewing files that changed from the base of the PR and between f8c28ec and cab784d.

📒 Files selected for processing (2)
  • src/app/core/authentication/authentication.guard.ts
  • src/app/login/login.component.ts

Comment thread src/app/login/login.component.ts
@Ruba-Tawk-FOO
Ruba-Tawk-FOO force-pushed the WEB-1077-redirect-to-requested-url-after-login branch from cab784d to 97a83fa Compare July 30, 2026 09:44
Preserve the attempted URL as a `returnUrl` query param when the authentication
guard redirects an unauthenticated user to the login page, and navigate back to
it after a successful login (falling back to the dashboard for missing/unsafe
values).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Ruba-Tawk-FOO
Ruba-Tawk-FOO force-pushed the WEB-1077-redirect-to-requested-url-after-login branch from 97a83fa to 9cd08a7 Compare July 30, 2026 13:39
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.

3 participants