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