Skip to content

fix: isolate codex login auth import#112

Merged
Loongphy merged 1 commit into
v0.2from
codex/v0.2-temp-login
May 21, 2026
Merged

fix: isolate codex login auth import#112
Loongphy merged 1 commit into
v0.2from
codex/v0.2-temp-login

Conversation

@Loongphy
Copy link
Copy Markdown
Owner

@Loongphy Loongphy commented May 21, 2026

Summary

Fix codex-auth login so adding a new account no longer lets upstream codex login touch the currently active auth.json.

This PR changes the login flow to:

  • create a temporary empty CODEX_HOME
  • run upstream codex login inside that temporary home
  • import the resulting auth.json into codex-auth's managed account store
  • activate the imported account by copying the auth snapshot into the real CODEX_HOME
  • clean up the temporary login home after the import

Closes: #110

Why

Recent Codex CLI versions revoke superseded managed ChatGPT tokens after a successful re-login. When codex-auth login previously ran upstream codex login directly against the real CODEX_HOME, logging in a new account could cause the previously active account's refresh token to be revoked server-side.

That breaks codex-auth's multi-account model: even if the old auth.json snapshot is still stored locally, it may no longer be usable after the upstream revoke request.

By running upstream login in an isolated temporary CODEX_HOME, there is no previous auth for Codex to revoke. codex-auth then imports the new login result and activates it through its existing file-copy based account switching flow.

What changed

  • Added runCodexLoginWithCodexHome(...) to run upstream codex login with a CODEX_HOME override.
  • Updated handleLogin to use a temporary login home instead of the real Codex home.
  • Imported the temporary login result into the managed account snapshot store.
  • Copied the imported auth into the real active auth.json only after upstream login completed successfully.
  • Added an e2e regression test for logging in while an existing active auth.json is present.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 21, 2026

Open in StackBlitz

@loongphy/codex-auth-darwin-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-arm64@112

@loongphy/codex-auth-darwin-x64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-x64@112

@loongphy/codex-auth-linux-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-arm64@112

@loongphy/codex-auth-linux-x64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-x64@112

@loongphy/codex-auth-win32-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-arm64@112

@loongphy/codex-auth-win32-x64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-x64@112

@loongphy/codex-auth

npx https://pkg.pr.new/@loongphy/codex-auth@112

commit: efcc04c

@Loongphy Loongphy force-pushed the codex/v0.2-temp-login branch from 17b4f46 to efcc04c Compare May 21, 2026 05:45
@Loongphy Loongphy merged commit aa6d1e4 into v0.2 May 21, 2026
11 checks passed
@Loongphy Loongphy deleted the codex/v0.2-temp-login branch May 21, 2026 05:49
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.

1 participant