mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Refine profile switching login flow
This commit is contained in:
1 parent
30895e4444
commit
12b1c1e7f8
1 file changed
+30
-5
@@ -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 };
|
||||
|
||||
Reference in new issue
Block a user