fix(auth): skip legacy OAuth repair when destination profile already exists (#97541)

When doctor --fix runs legacy OAuth profile id repair, it picks the
single non-legacy OAuth profile as the migration target. If that target
profile already exists as a separate user-configured account, the repair
unconditionally overwrites it, destroying the account's config
(displayName, email) and collapsing two distinct accounts into one.

Add a guard: if the destination profile id already exists in
cfg.auth.profiles, skip the repair entirely to preserve both accounts.
Also pass cfg to resolveAuthProfileMetadata so config-set displayName
is preserved when the repair does proceed.

Fixes #97522
This commit is contained in:
liuhao1024
2026-06-29 02:46:20 +08:00
committed by GitHub
parent 71347ef999
commit ee72fa7f5f
+9
View File
@@ -123,7 +123,16 @@ export function repairOAuthProfileIdMismatch(params: {
return { config: params.cfg, changes: [], migrated: false };
}
// Skip repair if destination profile already exists as a separate
// user-configured account. Overwriting it would destroy the existing
// account's config (displayName, email, etc.) and collapse two distinct
// accounts into one. See #97522.
if (params.cfg.auth?.profiles?.[toProfileId]) {
return { config: params.cfg, changes: [], migrated: false };
}
const { email: toEmail, displayName: toDisplayName } = resolveAuthProfileMetadata({
cfg: params.cfg,
store: params.store,
profileId: toProfileId,
});