Merge pull request #682 from PR0M3TH3AN/codex/fix-persistent-login-data-issue

Respect logout state during saved profile hydration
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2025-10-19 18:56:50 -04:00
commit e34e021339
2 files changed
+47 -17

No files matched your search

+7 -2
View File
@@ -119,8 +119,13 @@ export default class AuthService {
hydrateFromStorage() {
hydrateProfileCacheFromStorage();
const { profiles } = hydrateSavedProfilesFromStorage();
if (!getActiveProfilePubkey() && Array.isArray(profiles) && profiles.length) {
const { profiles, hasExplicitActiveProfile } = hydrateSavedProfilesFromStorage();
if (
!getActiveProfilePubkey() &&
!hasExplicitActiveProfile &&
Array.isArray(profiles) &&
profiles.length
) {
const first = profiles[0]?.pubkey || null;
if (first) {
setActiveProfilePubkey(first, { persist: true });
+40 -15
View File
@@ -34,6 +34,7 @@ function sanitizeProfileString(value) {
let savedProfiles = [];
let activeProfilePubkey = null;
let hadExplicitActiveProfile = false;
const profileCache = new Map();
const urlHealthCache = new Map();
const urlHealthInFlight = new Map();
@@ -297,14 +298,23 @@ export function persistSavedProfiles({ persistActive = true } = {}) {
export function loadSavedProfilesFromStorage() {
savedProfiles = [];
activeProfilePubkey = null;
hadExplicitActiveProfile = false;
if (typeof localStorage === "undefined") {
return { profiles: getSavedProfiles(), activePubkey: activeProfilePubkey };
return {
profiles: getSavedProfiles(),
activePubkey: activeProfilePubkey,
hasExplicitActiveProfile: hadExplicitActiveProfile,
};
}
const raw = localStorage.getItem(SAVED_PROFILES_STORAGE_KEY);
if (!raw) {
return { profiles: getSavedProfiles(), activePubkey: activeProfilePubkey };
return {
profiles: getSavedProfiles(),
activePubkey: activeProfilePubkey,
hasExplicitActiveProfile: hadExplicitActiveProfile,
};
}
let needsRewrite = false;
@@ -352,17 +362,28 @@ export function loadSavedProfilesFromStorage() {
savedProfiles.push(entry);
}
const activeCandidate =
typeof parsed.activePubkey === "string"
? parsed.activePubkey
: typeof parsed.activePubKey === "string"
? parsed.activePubKey
: null;
const normalizedActive = normalizeHexPubkey(activeCandidate);
if (normalizedActive && seenPubkeys.has(normalizedActive)) {
activeProfilePubkey = normalizedActive;
} else if (activeCandidate) {
needsRewrite = true;
let hasActiveField = false;
let activeCandidate;
if (Object.prototype.hasOwnProperty.call(parsed, "activePubkey")) {
hasActiveField = true;
activeCandidate = parsed.activePubkey;
} else if (Object.prototype.hasOwnProperty.call(parsed, "activePubKey")) {
hasActiveField = true;
activeCandidate = parsed.activePubKey;
}
if (hasActiveField) {
hadExplicitActiveProfile = true;
if (typeof activeCandidate === "string") {
const normalizedActive = normalizeHexPubkey(activeCandidate);
if (normalizedActive && seenPubkeys.has(normalizedActive)) {
activeProfilePubkey = normalizedActive;
} else if (activeCandidate) {
needsRewrite = true;
}
} else if (activeCandidate !== null && activeCandidate !== undefined) {
needsRewrite = true;
}
}
} else if (raw) {
needsRewrite = true;
@@ -372,7 +393,7 @@ export function loadSavedProfilesFromStorage() {
needsRewrite = true;
}
if (!activeProfilePubkey && savedProfiles.length) {
if (!activeProfilePubkey && savedProfiles.length && !hadExplicitActiveProfile) {
activeProfilePubkey = savedProfiles[0].pubkey;
needsRewrite = true;
}
@@ -381,7 +402,11 @@ export function loadSavedProfilesFromStorage() {
persistSavedProfiles();
}
return { profiles: getSavedProfiles(), activePubkey: activeProfilePubkey };
return {
profiles: getSavedProfiles(),
activePubkey: activeProfilePubkey,
hasExplicitActiveProfile: hadExplicitActiveProfile,
};
}
export function syncSavedProfileFromCache(pubkey, { persist = false } = {}) {