Skip to content

fix(login): keep the account session when logging in to a Personal Server - #38

Merged
volod-vana merged 1 commit into
mainfrom
fix/login-ps-session
Sep 17, 2026
Merged

volod-vana merged 1 commit into
mainfrom
fix/login-ps-session

Conversation

@volod-vana

Copy link
Copy Markdown
Member

What broke

Two separate faults in vana login, both hit while chasing why vana connect
reported "Personal Server sync failed / requires authentication".

1. Logging in to a Personal Server signed you out of your account.
saveCredentials rewrites the whole auth file. The self-hosted branch handed
it a freshly built account block:

account: {
  address: result.address,   // the SERVER OWNER's wallet, not your account
  session_token: "",         // a live account token, blanked
  expires_at: result.expires_at,
},

So vana login --server <url> silently replaced the CLI identity with
whoever owns that server and destroyed a valid account session. On a machine
where the CLI account and the local server owner differ, that is a real
identity swap with no warning and no confirmation.

2. vana login could not fix the state it had just diagnosed.
The server URL is resolved only from env vars and auth.json. With
personal_server: null the URL is unknown, so the command took the cloud
branch, saw a valid account token, printed Already logged in, and returned
0 having done nothing. It then suggested vana login --server <url> for a URL
it had detected through a different code path, and immediately below that
told the user to run vana logout first. Every connect kept failing with
MISSING_AUTH and the two printed remedies contradicted each other.

What changed

  • accountSessionToPreserve decides which account block survives a server
    login. A live session is carried across; a tokenless or env-sourced one is
    not persisted, so a first-time self-hosted user still gets seeded from the
    server owner as before.
  • When the server's owner differs from the signed-in account, the CLI now
    says so instead of quietly switching.
  • The already-logged-in path acquires the missing server session itself
    rather than printing the command back at the user. Gated on --no-input,
    and on the server actually being self-hosted, so agents and CI keep the old
    reporting behaviour.
  • The contradictory logout first line now reads as what it is: how to sign
    in as someone else.

The self-hosted flow moved into loginToPersonalServer so both entry points
share it. That move is most of the diff; the logic inside is unchanged apart
from the credential merge.

Test plan

  • pnpm validate (367 tests)
  • New unit tests cover all three branches of accountSessionToPreserve
  • Verified against a stub Personal Server in a throwaway HOME, before and
    after the fix. Before: account_address became the server owner and the
    token was emptied. After: account address and token intact, server
    session stored, mismatch reported.
  • Verified the already-logged-in path with a detected-but-unauthenticated
    server: plain vana login now completes the server login and writes
    personal_server, where it previously exited 0 with nothing saved.
  • Confirmed --no-input still takes the reporting path

…rver

`saveCredentials` rewrites the whole auth file, and the self-hosted branch
passed a freshly built account block with an empty token and the server
owner's address. Logging in to a Personal Server therefore signed the user
out of their account and silently switched the CLI identity to whoever owns
that server.

`vana login` could not repair the state it diagnosed either: the server URL
is resolved only from env and auth.json, so a machine with a detected but
unauthenticated server fell through to the cloud branch, reported "Already
logged in", and printed the very command it had just refused to act on.
That left `connect` failing every sync with MISSING_AUTH and no way out.

- carry a live account session across a server login, and say so when the
  server belongs to a different address
- acquire the server session from the already-logged-in path instead of
  suggesting it, unless --no-input
- stop telling the user to log out first when the advice above it is to log in
@volod-vana
volod-vana merged commit a665dc5 into main Sep 17, 2026
6 checks passed
@volod-vana
volod-vana deleted the fix/login-ps-session branch September 17, 2026 04:47
github-actions Bot pushed a commit that referenced this pull request Sep 17, 2026
## [0.23.13](v0.23.12...v0.23.13) (2026-09-17)

### Bug Fixes

* **login:** keep the account session when logging in to a Personal Server ([#38](#38)) ([a665dc5](a665dc5))
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.23.13 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant