From a1b67e71cd51003cae5f51ce927f6f9b6fa46ec6 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 15 Aug 2023 04:30:09 -0400 Subject: [PATCH] feat: add loginActivePortals function --- src/portal.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/portal.ts b/src/portal.ts index 40f6fae..3d3956c 100644 --- a/src/portal.ts +++ b/src/portal.ts @@ -4,6 +4,7 @@ import { deriveChildKey } from "#keys.js"; import { ed25519 } from "@noble/curves/ed25519"; import { bytesToHex } from "@noble/hashes/utils"; import COMMUNITY_PORTAL_LIST from "@lumeweb/community-portals"; +import { NO_PORTALS_ERROR } from "#err.js"; let activePortalMasterKey; @@ -138,3 +139,21 @@ export function loadSavedPortals(): Portal[] | null { return JSON.parse(portals); } + +export async function loginActivePortals() { + const activePortals = getActivePortals(); + + if (!activePortals.length) { + return; + } + + for (const portal of activePortals) { + if (!(await portal.isLoggedIn())) { + try { + await portal.register(); + } catch {} + + await portal.login(); + } + } +}