Fix local sign-in losing its user account (empty read-only workspace)#1739
Open
iyernaveenr wants to merge 1 commit into
Open
Fix local sign-in losing its user account (empty read-only workspace)#1739iyernaveenr wants to merge 1 commit into
iyernaveenr wants to merge 1 commit into
Conversation
The local auto-login response carried no user id, so the client stored none and every server-owned Space was filtered out client-side, leaving an empty read-only workspace. Return the user id from auto-login, recover it from the access token when a login response omits it, and repair already-persisted sessions at rehydrate so existing installs recover without signing in again. Signed-off-by: Naveen R. Iyer <iyernaveenr@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In fully local (self-hosted) mode, the app can end up showing only an empty, read-only "Legacy Space": no Projects in the sidebar, composer disabled with "Legacy Spaces are read-only", and no way to pick a model -- even though all of the user's Spaces, Projects, and chat history are intact on the server.
Root cause
The local auto-login endpoint (
POST /api/v1/user/auto-login) returns onlytokenandemail-- no user id. The client'ssetAuththerefore storesuser_id: null. Space hydration filters server Spaces by ownership, comparing each Space'suser_idagainst the canonicalized local id; with no id, the canonical value is thelocalsentinel, which matches nothing, so every server-owned Space is silently discarded and only the locally fabricated legacy Space remains. The access token itself carries the user id in its payload the whole time; the client just never read it.Fix
user_idin the auto-login response (LoginResponsegains an optionaluser_id).setAuth(defensive for all login paths).Testing
user_id: null, valid token): Space list showed only "Legacy Space" while an authenticated/api/v1/spacesrequest returned all Spaces. After the fix, reloading the app recovers the id from the token and the user's Spaces and Projects reappear.POST /api/v1/user/auto-loginnow returnsuser_id(verified against a running local server).tscpasses; the changed server files compile; store test suites pass. Token-decoding helper handles malformed/absent tokens by returning null (no behavior change for the hosted login path, which already supplies an id).