feat: separate interface for decoded accounts

This commit is contained in:
2025-05-24 14:24:50 +02:00
parent eee3839dea
commit 92fda8cb24

View File

@ -2,7 +2,7 @@ import { useDbContext } from "@/context/db/db";
import { deriveDeviceKey, getDeviceId } from "@/util/deviceId"; import { deriveDeviceKey, getDeviceId } from "@/util/deviceId";
import { useCallback } from "react"; import { useCallback } from "react";
export interface LocalAccount { export interface RawLocalAccount {
accountId: string; accountId: string;
label: string; label: string;
email: string; email: string;
@ -11,6 +11,15 @@ export interface LocalAccount {
updatedAt: string; updatedAt: string;
} }
export interface LocalAccount {
accountId: string;
label: string;
email: string;
access: string;
refresh: string;
updatedAt: string;
}
export interface CreateAccountRequest { export interface CreateAccountRequest {
accountId: string; accountId: string;
label: string; label: string;
@ -96,25 +105,28 @@ export const useAccountRepo = () => {
const tx = db.transaction("accounts", "readonly"); const tx = db.transaction("accounts", "readonly");
const store = tx.objectStore("accounts"); const store = tx.objectStore("accounts");
const accounts: LocalAccount[] = await store.getAll(); const accounts: RawLocalAccount[] = await store.getAll();
const results = []; const results: LocalAccount[] = (
for (const account of accounts) { await Promise.all(
try { accounts.map(async (account) => {
const accessToken = await decryptToken(account.access); try {
const refreshToken = await decryptToken(account.refresh); const accessToken = await decryptToken(account.access);
results.push({ const refreshToken = await decryptToken(account.refresh);
accountId: account.accountId, return {
label: account.label, accountId: account.accountId,
email: account.email, label: account.label,
access: accessToken, email: account.email,
refresh: refreshToken, access: accessToken,
updatedAt: account.updatedAt, refresh: refreshToken,
}); updatedAt: account.updatedAt,
} catch (err) { };
console.warn(`Failed to decrypt account ${account.label}:`, err); } catch (err) {
} console.warn(`Failed to decrypt account ${account.label}:`, err);
} }
})
)
).filter((acc) => acc !== undefined);
return results; return results;
}, [db, decryptToken]); }, [db, decryptToken]);