Fix mobile account session selection

This commit is contained in:
2026-06-29 22:01:41 -04:00
parent 9498a09b5b
commit b7eef743bd
9 changed files with 286 additions and 27 deletions
+19 -2
View File
@@ -13,6 +13,23 @@ export type SavedAccount = {
lastUsedAt: number;
};
function isSavedAccount(value: unknown): value is SavedAccount {
if (!value || typeof value !== "object") return false;
const account = value as Partial<SavedAccount>;
return (
typeof account.id === "string" &&
account.id.length > 0 &&
typeof account.instanceUrl === "string" &&
account.instanceUrl.length > 0 &&
typeof account.userId === "string" &&
account.userId.length > 0 &&
typeof account.email === "string" &&
typeof account.name === "string" &&
typeof account.lastUsedAt === "number"
);
}
export function buildAccountId(instanceUrl: string, userId: string) {
const host = instanceUrl.replace(/^https?:\/\//, "").replace(/\/$/, "");
return `${host}::${userId}`;
@@ -26,8 +43,8 @@ export async function loadAccounts(): Promise<SavedAccount[]> {
const raw = await AsyncStorage.getItem(ACCOUNTS_KEY);
if (!raw) return [];
try {
const parsed = JSON.parse(raw) as SavedAccount[];
return Array.isArray(parsed) ? parsed : [];
const parsed = JSON.parse(raw) as unknown;
return Array.isArray(parsed) ? parsed.filter(isSavedAccount) : [];
} catch {
return [];
}