Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,17 @@ async function persistAccountPool(
}

// Update existing account (this handles both email match and token match cases)
// When email matches but token differs, this effectively replaces the old token
// When email matches but token differs, this effectively replaces the old token.
// Existing (disk) projectId/managedProjectId take priority over incoming
// (OAuth-fetched) values to prevent auto-detected fallbacks from overwriting
// manually configured project IDs.
const oldToken = existing.refreshToken;
accounts[existingIndex] = {
...existing,
email: result.email ?? existing.email,
refreshToken: parts.refreshToken,
projectId: parts.projectId ?? existing.projectId,
managedProjectId: parts.managedProjectId ?? existing.managedProjectId,
projectId: existing.projectId ?? parts.projectId,
managedProjectId: existing.managedProjectId ?? parts.managedProjectId,
lastUsed: now,
};

Expand Down
9 changes: 6 additions & 3 deletions src/plugin/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,14 @@ export class AccountManager {

updateFromAuth(account: ManagedAccount, auth: OAuthAuthDetails): void {
const parts = parseRefreshParts(auth.refresh);
// Preserve existing projectId/managedProjectId if not in the new parts
// Preserve existing (disk-loaded) projectId/managedProjectId over runtime values.
// The account's existing values may have been manually configured by the user;
// the auth refresh string may contain an auto-detected fallback that should not
// overwrite those manual edits.
account.parts = {
...parts,
projectId: parts.projectId ?? account.parts.projectId,
managedProjectId: parts.managedProjectId ?? account.parts.managedProjectId,
projectId: account.parts.projectId ?? parts.projectId,
managedProjectId: account.parts.managedProjectId ?? parts.managedProjectId,
};
account.access = auth.access;
account.expires = auth.expires;
Expand Down
8 changes: 5 additions & 3 deletions src/plugin/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ function mergeAccountStorage(existing: AccountStorageV3, incoming: AccountStorag
accountMap.set(acc.refreshToken, {
...existingAcc,
...acc,
// Preserve manually configured projectId/managedProjectId if not in incoming
projectId: acc.projectId ?? existingAcc.projectId,
managedProjectId: acc.managedProjectId ?? existingAcc.managedProjectId,
// Preserve manually configured projectId/managedProjectId from disk.
// Existing (disk) values take priority over incoming (in-memory) values
// to prevent auto-detected fallback IDs from overwriting user edits.
projectId: existingAcc.projectId ?? acc.projectId,
managedProjectId: existingAcc.managedProjectId ?? acc.managedProjectId,
rateLimitResetTimes: {
...existingAcc.rateLimitResetTimes,
...acc.rateLimitResetTimes,
Expand Down