Skip to content

Conversation

@grv-saini-20
Copy link
Collaborator

@grv-saini-20 grv-saini-20 commented Jan 30, 2026

Description of change

fixed the issue when user cast its vote if not loggedin to the evoting it will take the user to the root page after successful login instead of navigating the user to that particular vote page (voteid).

Issue Number

Closes #703

Type of change

  • Update (a change which updates existing functionality)
  • Fix (a change which fixes an issue)

How the change has been tested

Manual

Change checklist

  • I have ensured that the CI Checks pass locally
  • I have removed any unnecessary logic
  • My code is well documented
  • I have signed my commits
  • My code follows the pattern of the application
  • I have self reviewed my code

Summary by CodeRabbit

  • New Features

    • Login now accepts a redirect destination from the URL and preserves it across auto-login and background login flows, then navigates there after authentication.
  • Bug Fixes

    • Fixed mobile login UI text.
    • Ensures stored post-login redirect is cleared after use.

✏️ Tip: You can customize this high-level summary in your review settings.

@grv-saini-20 grv-saini-20 self-assigned this Jan 30, 2026
@grv-saini-20 grv-saini-20 requested a review from coodos as a code owner January 30, 2026 10:02
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

Parses and validates a redirect query parameter into redirectTo (and sessionStorage), then uses that stored value after successful authentication (auto-login or SSE) to navigate the user, clearing the sessionStorage key afterwards. Also includes a minor UI text change and formatting tweaks.

Changes

Cohort / File(s) Summary
Login redirect & auth flow
platforms/eVoting/src/app/(auth)/login/page.tsx
Added redirectTo state and validation for redirect query param; stores valid redirect in sessionStorage.postLoginRedirect. Both auto-login and SSE success handlers now resolve redirect using sessionStorageredirectTo/, perform navigation, and clear the storage key. SSE listener dependency array extended to include redirectTo. Minor UI text change (mobile copy) and whitespace/newline formatting adjustments.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant LoginPage
  participant SessionStorage
  participant AuthService
  participant Router

  User->>LoginPage: Open /login?redirect=/vote/123
  LoginPage->>LoginPage: parse & validate `redirect` → `redirectTo`
  LoginPage->>SessionStorage: set `postLoginRedirect` = "/vote/123"
  Note over AuthService,LoginPage: Authentication attempt (auto-login or SSE)
  AuthService-->>LoginPage: auth success
  LoginPage->>SessionStorage: read `postLoginRedirect`
  alt postLoginRedirect exists
    LoginPage->>Router: navigate to "/vote/123"
    LoginPage->>SessionStorage: clear `postLoginRedirect`
  else fallback to redirectTo or "/"
    LoginPage->>Router: navigate to `redirectTo` or "/"
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hopped in with a query bright,
A little redirect saved the night,
SessionStorage kept the key,
Now voters find their way back with glee,
Hooray — a hop, a click, and flight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: user-redirection-when-voting' directly and specifically describes the main change, which addresses user redirection during the voting process after login.
Description check ✅ Passed The description covers all required sections: change description, issue number, type of change, testing method, and completed checklist items following the template structure.
Linked Issues check ✅ Passed The code changes implement the core requirement from issue #703: preserving the redirect URL when a user logs in, so they are returned to the voting page instead of the home page.
Out of Scope Changes check ✅ Passed All changes are focused on fixing the redirect behavior in the login page; however, a minor typo fix ('you' to 'your') is present but unrelated to the primary objective.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/user-redirection-when-voting

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
Contributor

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
platforms/eVoting/src/app/(auth)/login/page.tsx (2)

17-47: ⚠️ Potential issue | 🟠 Major

Persist redirect before the auto-login early return.

Right now the effect returns early when ename/session/signature exist, so the redirect param is never stored. That means deep-link auto-login will still fall back to / even if a redirect was supplied.

✅ Suggested fix (store redirect before the early return)
-        if (ename && session && signature) {
-            // Clean up URL
-            window.history.replaceState({}, '', window.location.pathname);
-            
-            // Auto-submit login
-            handleAutoLogin(ename, session, signature, appVersion || '0.4.0');
-            return;
-        }
-
-        if (redirect && redirect.startsWith("/") && !redirect.startsWith("//")) {
-        setRedirectTo(redirect);
-        sessionStorage.setItem("postLoginRedirect", redirect);
-    }
+        if (redirect && redirect.startsWith("/") && !redirect.startsWith("//")) {
+            setRedirectTo(redirect);
+            sessionStorage.setItem("postLoginRedirect", redirect);
+        }
+
+        if (ename && session && signature) {
+            // Clean up URL
+            window.history.replaceState({}, '', window.location.pathname);
+            
+            // Auto-submit login
+            handleAutoLogin(ename, session, signature, appVersion || '0.4.0');
+            return;
+        }

184-193: ⚠️ Potential issue | 🟡 Minor

Fix the mobile prompt typo.

“using you” should be “using your”.

✏️ Proposed edit
-                                <span>Click the button below using you</span>
+                                <span>Click the button below using your</span>

@coodos coodos merged commit 2434cb2 into main Jan 30, 2026
4 checks passed
@coodos coodos deleted the fix/user-redirection-when-voting branch January 30, 2026 13:07
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.

[Bug] User is redirected to home page instead of vote after login from chat

3 participants