Refine profile switching login flow

This commit is contained in:
thePR0M3TH3AN committed 2025-10-09 18:41:27 -04:00
1 parent 30895e4444
commit 12b1c1e7f8
1 file changed
+30 -5
+30 -5
View File
@@ -591,16 +591,33 @@ export default class AuthService {
return { switched: false, reason: "already-active" };
}
const requestOptions = {
allowAccountSelection: true,
expectPubkey: normalizedTarget,
persistActive: true,
};
const autoApply = requestOptions.autoApply !== false;
let requestResult;
try {
await this.requestLogin({
allowAccountSelection: true,
expectPubkey: normalizedTarget,
});
requestResult = await this.requestLogin(requestOptions);
} catch (error) {
throw error;
}
const detail = await this.login(normalizedTarget, { persistActive: true });
const requestedPubkey =
this.normalizeHexPubkey(requestResult?.pubkey) ||
(typeof requestResult?.pubkey === "string"
? requestResult.pubkey.trim()
: "");
let detail = requestResult?.detail || null;
if (!detail && !autoApply) {
const fallbackTarget =
this.normalizeHexPubkey(requestedPubkey) || requestedPubkey || normalizedTarget;
detail = await this.login(fallbackTarget, { persistActive: true });
}
mutateSavedProfiles((profiles) => {
const draft = profiles.slice();
@@ -614,6 +631,14 @@ export default class AuthService {
return draft;
}, { persist: true, persistActive: true });
const savedProfiles = this.cloneSavedProfiles();
const activeProfilePubkey = getActiveProfilePubkey();
if (detail && typeof detail === "object") {
detail.savedProfiles = savedProfiles;
detail.activeProfilePubkey = activeProfilePubkey;
}
this.emitProfileList("switch-profile");
return { switched: true, detail };