openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

fix: redirect to home after login (#2726)

Open Sushanth012 opened this issue 6 months ago • 4 comments

Issue Fixed

  • Fixes #2726: After successful login, users are now automatically redirected to their dashboard/home page.

What was broken

  • After successful OAuth or magic link login, session state was patched to a non-React/global store instead of the React context, so UI and routing logic did not detect the new session and did not redirect users.

Fix

  • Added a listener in the main app shell to handle the session token update event. It updates the React context (via storeSessionToken). The routing guards then automatically route users home on login.
  • No changes to logout, signup, or other flows.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced session token management to properly synchronize token updates across the application, ensuring consistent session state during active sessions.

Review Change Stack

Sushanth012 avatar May 27 '26 05:05 Sushanth012

📝 Walkthrough

Walkthrough

AppShell now subscribes to a core-state:session-token-updated browser event via useEffect. When the event fires with a sessionToken in its details, the app updates its core session state by calling storeSessionToken. The listener is properly cleaned up when the component unmounts or the dependency changes.

Changes

Session Token Event Synchronization

Layer / File(s) Summary
Session token update event listener
app/src/App.tsx
A useEffect hook in AppShell registers a listener for the core-state:session-token-updated custom event. When fired with event.detail.sessionToken, it updates app session state via storeSessionToken() and cleans up the listener on unmount.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through event streams so bright, Catching token updates mid-flight! AppShell listens, storeSessionToken calls, Session state syncs through digital halls. ✨

🚥 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 'fix: redirect to home after login' directly matches the main objective: automatically redirecting users to home after successful login.
Linked Issues check ✅ Passed The code change adds a listener for session token updates and syncs React context, directly addressing issue #2726's root cause of missing session state synchronization preventing post-login redirect.
Out of Scope Changes check ✅ Passed The changes are narrowly scoped to session token synchronization in App.tsx, directly addressing the linked issue with no unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
⚔️ Resolve merge conflicts
  • [ ] Resolve merge conflict in branch main

[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

coderabbitai[bot] avatar May 27 '26 05:05 coderabbitai[bot]

Issue Fixed

What was broken

  • After successful OAuth or magic link login, session state was patched to a non-React/global store instead of the React context, so UI and routing logic did not detect the new session and did not redirect users.

Fix

  • Added a listener in the main app shell to handle the session token update event. It updates the React context (via storeSessionToken). The routing guards then automatically route users home on login.
  • No changes to logout, signup, or other flows.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced session token management to properly synchronize token updates across the application, ensuring consistent session state during active sessions.

Review Change Stack

still not working

Pixel20coder avatar May 27 '26 07:05 Pixel20coder

@Sushanth012 this PR has merge conflicts with main — please rebase/resolve before review.

graycyrus avatar May 27 '26 19:05 graycyrus

This PR has merge conflicts with main — please rebase/resolve before review.

graycyrus avatar May 27 '26 19:05 graycyrus

Hi @Sushanth012 — thank you for taking the time to investigate this and open a PR! We appreciate the contribution.

After tracing the login flow carefully, we're closing this PR because the described issue does not exist in the current codebase. Here's the detailed reasoning:

Why this bug doesn't exist

The PR claims: session state is patched to a non-React/global store after login, so the React context never sees the new session and the redirect doesn't happen.

What the code actually does:

  1. desktopDeepLinkListener.ts → applySessionToken() dispatches the core-state:session-token-updated custom event after writing the token (line 100).

  2. CoreStateProvider.tsx already listens for that exact event (the onSessionTokenUpdated handler inside a useEffect). When it fires, it calls refresh() → fetchCoreAppSnapshot → commitState() — which is precisely the React context update path. The event was never ignored.

  3. The redirect to /home is already handled inside handleAuthDeepLink in desktopDeepLinkListener.ts. It polls the module-level snapshot to confirm commitState has run (i.e. currentUser + sessionToken are both populated), then sets window.location.hash = '/home'.

What the PR's change would actually do

Adding a second listener for core-state:session-token-updated in AppShell that calls storeSessionToken() results in:

  • A duplicate storeSession() Tauri IPC call — the session was already stored by applySessionToken.
  • A duplicate refresh() call — CoreStateProvider's existing listener already triggers this.

This introduces a double-write race on every deep-link login rather than fixing anything.


If you're seeing a real redirect failure after login, it's likely environment-specific (timing, a stale build, etc.). Feel free to open a new issue with reproduction steps and we can look into it properly. Thanks again for the effort!

M3gA-Mind avatar May 28 '26 12:05 M3gA-Mind