openhuman
openhuman copied to clipboard
Fix account switching causing data loss and forced re-onboarding after re-login
Summary
Fix account switching/session persistence bug where logging out, logging into another account, then returning to the first account causes full re-onboarding and loss of prior chat/login/connection data.
Problem
When a user:
- logs out of account 1,
- logs into account 2,
- logs back into account 1,
the app treats account 1 like a fresh user and sends them through the full onboarding/login flow again. Existing account 1 data appears missing, including:
- chat history
- login/session state
- connected integrations / connection data
Expected Behavior
- Returning to account 1 should restore account 1 state.
- Existing chat history should remain available.
- Connected integrations should remain linked.
- User should not be forced through full onboarding again unless account truly has no onboarding state.
Scope
- Reproduce logout/account-switch/account-return flow.
- Audit account-scoped storage and persisted state keys.
- Ensure chat data, login data, onboarding completion, and connection data are scoped per account/user ID.
- Fix any state reset/clear logic that wipes all accounts instead of active account/session only.
- Rehydrate correct account state after login.
- Add safeguards to prevent cross-account data leakage while preserving each account's own data.
- Add logs for account switch, state clear, and state restore operations.
Acceptance Criteria
- Account 1 data is restored after switching to account 2 and back.
- User is not re-onboarded if account 1 already completed onboarding.
- Chat history and integrations remain attached to the correct account.
- Logging out does not delete persistent account data unless explicitly requested.
- No cross-account data leakage occurs.
- Tests cover account switch and re-login persistence behavior.
Linked to parent issue #972.
The issue has already been fixed and no further updation is needed for this issue. Tested it end to end! When I tested it end to end, the messages and connections persists for account 1.